Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically updating table based on current Form

Status
Not open for further replies.

cohortq

Technical User
Aug 20, 2002
20
US
Hey Guys!!
I am trying to update an access table using the RunSql function in access. I want to be able to update a single column each time with the ID# on the current form. Here is my code:
Dim NEWID As Integer
NEWID = Me.UniqueKey.Value (also tried without .value)
DoCmd.RunSQL "Update ID set Key = NEWID where UID = 1"
DoCmd.RunMacro "Export"

This is to printout the current form to a file, but the thing is that when I run it, Access wants to knowthe value for NEWID, and I thought I already set it. I think it's because Variables aren't applicable in an SQL statement, but I was wondering if anyone has suggestions on how I can do this. THANX GUYS!!!!
 
I realised not long ago that the sql statement cannot have the variable name in it within the quotes.
Your statement might work rewritten like that:

"Update ID set Key = " & NEWID & " where UID = 1"

If you had a string to pass instead of a number,

"Update ID set Key = NEWID where myString = '" & _
strData & "'"

As you can see, the string variable needs the single quote, which are part of the main sql statement, one before closing the sql, then the string variable, finally the ending single quote within the double quotes as it is part of the main sql statement.

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top