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!

UPDATE query

Status
Not open for further replies.

sanjna000

Programmer
Aug 1, 2003
132
GB
I am trying to update one of my tables using VBA. My code is as follows:

Sub UpdateChildAccounts(selItem As String)
Dim wrkJet As DAO.Workspace
Dim db As DAO.Database
Dim dbname As String
Dim rs As DAO.Recordset
Dim strSQL As String
Dim Q As DAO.QueryDef

dbname = "C:\Documents and Settings\Sanju\Desktop\Project\Commcare.mdb"
Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)
Set db = wrkJet.OpenDatabase(dbname, , True, "Microsoft.Jet.OLEDB.3.51")
Set Q = db.CreateQueryDef("")
strSQL = "UPDATE ClientAccountMapping" & _
" SET (ClientAccountMapping.InvoiceCode)='RBK'" & _
" WHERE (((ClientAccountMapping.InvoiceCode)='" & selItem & "'));"
Q.Sql = strSQL
Q.Close
End Sub

I am getting a syntax error in UPDATE query. I cannot see anything wrong in there. I hope some can help me to find my error.

Thanks a lot for u r help in advance.
Sanjna...
 
Try removing the semicolon. I know that MS Access always appends one to the end of each command in a query window, but I've never used it with DAO.
 
I use SELECT statement with the semi colon, it didn't give any prob. I guess there should be something else wrong with it.
 
What about this ?
strSQL = "UPDATE ClientAccountMapping" & _
" SET InvoiceCode='RBK'" & _
" WHERE InvoiceCode='" & Replace(selItem, "'", "''") & "'"


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
When I tried this it objected to the parenthesis in
"SET (ClientAccountMapping.InvoiceCode)='RBK'"

Oddly enough, I did not receive a syntax error concerning the (ClientAccountMapping.InvoiceCode)in the WHERE section.
 
PH,

I used u r code. It generated an error by highlighting 'replace' stating that sub function not defined. Do i have to give reference?

Thanks for u r help!
Sanjna...
 
Seems you have an old access ...
What about this ?
strSQL = "UPDATE ClientAccountMapping" & _
" SET InvoiceCode='RBK'" & _
" WHERE InvoiceCode=' & selItem & "'"


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
You have to execute the query ...
Q.Execute

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PH,
I did execute the query. It didn't give any error but still not updating the table.
 
Is there any way that i can run UPDATE query without using query def?
 
I tried to use following code. But it gave me an error stating variable not defined. Is any reference needs?

DoCmd.setWarnings False
DoCmd.RunSQL strSQL
DoCmd.setWarnings True

I really appriciate u r help!
Sanjna...
 
Can you please post the code of the whole sub saying us which line is highlighted when in debug mode ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top