Link to home
Start Free TrialLog in
Avatar of Fordraiders
FordraidersFlag for United States of America

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 ?

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

Open in new window



Thanks
fordraiders
ASKER CERTIFIED SOLUTION
Avatar of James Elliott
James Elliott
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Fordraiders

ASKER

Thanks Guys !!!
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]
"you might want to consider using Tempvars "
Double ditto on that ... a much more elegant solution,

mx