mud2
10-18-2007, 09:09 AM
This is so IMPORTANT that I MUST report...perhaps it is known already.
You can write your own functions and use them in SQL statements. As example,
I have a form, with a control button taht sarts the process. A table is created (SQL)...an input value is requested (InputBox), this value is passed to a user-written function embedded in an INSERT INTO sql...
The function MUST(?) be in a separate MODULE1!
Private Sub Command7_Click()
Dim sqlCreate As String
Dim SqlCall As String
Dim ThisFunction As Integer
Dim ThisData As Integer
ThisData = InputBox("Enter an Integer")
sqlCreate = "Create Table MyFunction (Function_Return number);"
SqlCall = "Insert into MyFunction (Function_Return) Values (ThisFunction(" & ThisData & "));"
'SqlCall = "Insert into MyFunction (Function_Return) Values (ThisFunction(300));"
'DoCmd.RunSQL sqlCreate
DoCmd.RunSQL SqlCall
End Sub
' *************************************************************************** ********************
'In a separate MODULE:
Option Compare Database
Option Explicit
Public Function ThisFunction(Data As Integer) As Integer
ThisFunction = 5 * Data
End Function
The implications are enormous...
You can write your own functions and use them in SQL statements. As example,
I have a form, with a control button taht sarts the process. A table is created (SQL)...an input value is requested (InputBox), this value is passed to a user-written function embedded in an INSERT INTO sql...
The function MUST(?) be in a separate MODULE1!
Private Sub Command7_Click()
Dim sqlCreate As String
Dim SqlCall As String
Dim ThisFunction As Integer
Dim ThisData As Integer
ThisData = InputBox("Enter an Integer")
sqlCreate = "Create Table MyFunction (Function_Return number);"
SqlCall = "Insert into MyFunction (Function_Return) Values (ThisFunction(" & ThisData & "));"
'SqlCall = "Insert into MyFunction (Function_Return) Values (ThisFunction(300));"
'DoCmd.RunSQL sqlCreate
DoCmd.RunSQL SqlCall
End Sub
' *************************************************************************** ********************
'In a separate MODULE:
Option Compare Database
Option Explicit
Public Function ThisFunction(Data As Integer) As Integer
ThisFunction = 5 * Data
End Function
The implications are enormous...