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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do I write back to a table?

Status
Not open for further replies.

kskip

MIS
Apr 23, 2003
16
US
I have code that does a dlookup on a table with one row, one field. In my code I add 1 to that number and now I want to write the new number back to the table. How do I do that?
 


DLookUp is read only. You will need to create an SQL update.

Code:
' stupid example
Update tblWhatever SET fldMine = 'XYZ ' WHERE fldyours = '21'

[thumbsup2]
 
now if get an Error "Syntax Error"
here's my code

Code:
  Dim varX As Variant
   varX = DLookup("[upccode]", "nextupc", "[upccode] > 1")

   
  'add 1 to that # and write it back
  Dim varY As Variant
  varY = Val(varX) + 1
  
   Update nextupc SET upccode = varY where upccode = varX
 
Code:
dim strSQL As String

With Currentdb.openrecordset("SELECT upccode FROM nextupc WHERE upccode > 1")
     Do Until .EOF
     .Edit
     .Fields("upccode") = .Fields("upccode") + 1
     .Update
     Loop
End With

Hope this helps.

-------------------------
Just call me Captain Awesome.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top