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

Need help with Update query syntax

Status
Not open for further replies.

SAM453

Programmer
Jun 6, 2011
18
US
Private Sub Command21_Click()
Can any one tell me wats wrong in my code??? it says i should use dbsee changes .... I don't what it is. Can you please give me the correct syntax for me. Here SID is the identity propery in sql table. I'm just testing 2 columns here but ihave more than 10 columns to update. Plz give me a syntax to support this.


Dim db As DAO.Database
Dim stSQL As String

stSQL = "update Lkp_Store1 " & _
"set Facility_Number='" & (Text8) & "',[Station]='" & (Text0) & "'" & _
" where SID = " & Me.Combo7.Value & ""

CurrentDb.Execute stSQL

MsgBox "New Record Updated.", vbInformation, "Successful Transaction"
End Sub

Thanks,
SAM
 
It looks like your tables are linked so insted of the Execute method, try

Code:
docmd.RunSQL stSQL

In your set line building the SQL it looks like you are using control names. Typically in VBA when the code is on the form people just precede the control with ME! in order to get the value as controls is the default collection (!) of the form (Me) and the value is the default property. Not specifying the form can lead to compiling issues.... rather than understand that particular nuance, I just use the FQN's...

Code:
'Dim db As DAO.Database
Dim stSQL As StringstSQL = "update Lkp_Store1 " & _
"set Facility_Number='" & (Text8) & "',[Station]='" & (Text0) & "'" & _
" where SID = " & Me.Combo7.Value & ""

'CurrentDb.Execute stSQL
docmd.RunSQL stSQL

MsgBox "New Record Updated.", vbInformation, "Successful Transaction"

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top