Update Query error (1 Viewer)

ethan.geerdes

Registered User.
Local time
Today, 14:37
Joined
Jun 4, 2015
Messages
116
So I'm working on making an update query for a trouble ticket log (more or less) and I'm trying to set the status based on the ID number of the ticket.

My table is set up like this

Table name = tlbTSLog
first column = ID (pk)
second column= Submitted (date/time format)
third column= Date Updated (date/time format)
fourth Column= Completed (date/time format)
fifth column= Equipment (text)
sixth column= Problem (text)
seventh column= Actions taken (text)
eighth column= Resolution (text)
ninth column= Status (text)


My form has a combo box named combo10 label:ID

my update query is as follows.

Dim strSQL As String
strSQL = "Update tblTSLog" & _
" Set Status = 'in progress' , " & _
" [Date Updated] = #" & Now & "# ," & _
" Where [ID] = '" & Me.Combo10 & "';"

Debug.Print strSQL
CurrentDb.Execute strSQL, dbFailOnError


End Sub


I get a syntax error and it highlights the line

CurrentDb.Execute strSQL,dbFailOnError
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 14:37
Joined
Aug 30, 2003
Messages
36,125
It would help to see the result of the print, but the comma before "Where" will cause an error.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 14:37
Joined
Aug 30, 2003
Messages
36,125
Also, if ID is numeric, you don't want the single quotes around the value.
 

ethan.geerdes

Registered User.
Local time
Today, 14:37
Joined
Jun 4, 2015
Messages
116
I took the comma out and now I get a "data type mismatch" error.
 

Minty

AWF VIP
Local time
Today, 22:37
Joined
Jul 26, 2013
Messages
10,371
Did you remove the single quotes around your

" Where [ID] = '" & Me.Combo10 & "';"

As Paul suggested?
 

ethan.geerdes

Registered User.
Local time
Today, 14:37
Joined
Jun 4, 2015
Messages
116
Well, I did what I thought he said, and played with the syntax a little bit doesn't fail now but it also doesn't do what I'm trying to make it do.

This is what I currently have. Where do I go to find out more about the syntax about SQL in access? Thanks guys for your help by the way.


Private Sub Command8_Click()

Dim strSQL As String
strSQL = "Update tblTSLog" & _
" Set Status = 'in progress' , " & _
" [Date Updated] = #" & Now & "# " & _
" Where ID = " & Me.Combo10 & " ;"

Debug.Print strSQL
CurrentDb.Execute strSQL, dbFailOnError


End Sub
 

Minty

AWF VIP
Local time
Today, 22:37
Joined
Jul 26, 2013
Messages
10,371
In the Debug / VBA window open the immediate window (Press ctrl + G) you should see the actual text that strSql is using.

If the problem isn't immediately obvious, copy and paste it into the SQL view of a new blank query. Try and run it , what error comes back if any or look at it in datasheet view and see how many records it pulls in.
 

ethan.geerdes

Registered User.
Local time
Today, 14:37
Joined
Jun 4, 2015
Messages
116
I am starting to suspect that the query works and it is something with my form properties. I took the where line out and it updates status of everything to in progress. I then re-inserted the line and it's not erroring out however, it also won't update the record that is selected in the combo box.
 

Minty

AWF VIP
Local time
Today, 22:37
Joined
Jul 26, 2013
Messages
10,371
What is the bound column of your combo box?

add Debug.Print Me.Combo10 before your code.
 

ethan.geerdes

Registered User.
Local time
Today, 14:37
Joined
Jun 4, 2015
Messages
116
I figured it out. I didn't have the column specified in the combo box in the query.


Private Sub Command8_Click()

Dim strSQL As String
strSQL = "Update tblTSLog" & _
" Set Status = 'in progress' , " & _
" Where ID = " & Me.Combo10.Column(0) & " ;"

Debug.Print strSQL
CurrentDb.Execute strSQL, dbFailOnError


End Sub

and that worked! Thank you guys!
 

Users who are viewing this thread

Top Bottom