Fordraiders
asked on
pass global variable to Update query
access 2010
Trying to pass a global variable to an update query ?
This keeps prompting me a parameter query ?
Thanks
fordraiders
Trying to pass a global variable to an update query ?
This keeps prompting me a parameter query ?
Public Function ReturnVariable()
ReturnVariable = str
End Function
Dim strSQL As String
str = Me.List4.Value
'build the SQL string
strSQL = "UPDATE"
strSQL = strSQL & " tbl_History_Import_Flag "
strSQL = strSQL & "SET "
strSQL = strSQL & "tbl_History_Import_Flag.Field2 = "
strSQL = strSQL & ReturnVariable ' also tried just str
strSQL = strSQL & ";"
With DoCmd
.RunSQL strSQL
End With
Thanks
fordraiders
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you might want to consider using Tempvars instead of globally defined variables. The big advantages of a tempvar are:
1. it retains its value even after encountering an unhandled error, which will reset regular global variables.
2. you can set it in the immediate window, so you can test your query without having the rest of the application running.
3. you can refer to them as:
Tempvars!yourTempVar
Tempvars("YourTempVar")
[Tempvars]![yourTempvar]
1. it retains its value even after encountering an unhandled error, which will reset regular global variables.
2. you can set it in the immediate window, so you can test your query without having the rest of the application running.
3. you can refer to them as:
Tempvars!yourTempVar
Tempvars("YourTempVar")
[Tempvars]![yourTempvar]
"you might want to consider using Tempvars "
Double ditto on that ... a much more elegant solution,
mx
Double ditto on that ... a much more elegant solution,
mx
ASKER