1
votes

I'm trying to update records in my form. It's a restaurant reservation system. Given the Table #, the form can let the user input the Customer ID of the person reserving, the reservation time and date. But when I click on the "update" button in my form, a text box will pop up with this:

enter image description here

And whatever I put in it, the runtime error "too few parameters. expected 1." pops up. Sometimes a "Reserved Error" will pop up. Could someone help me? It's the last step before I could finally finish this project.

This is my code for updating the record:

Private Sub Command8_Click()
On Error GoTo errHandling

Dim strSQL As String

strSQL = "UPDATE tblReserve SET CustomerID = " & """" & Me.txtCustID & """" & _
", ResDate = " & """" & Me.txtResDate & """" & ", ResTime = " & """" & Me.txtTime &      """" & " WHERE TableNum =" & Me.TableNum

DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
CurrentDb.Execute strSQL, dbFailOnError

DoCmd.Close
Exit Sub
errHandling:
MsgBox Err.Description
End Sub

enter image description here

Screenshot of VBA editor with Debug.Print strSQL

2
Add a Debug.Print strSQL statement after you've constructed your SQL string, then copy it from the Immediate Window ([Crtl-G] in the VBA editor) and update your question (click the "edit" link, above) to show us the SQL you are actually trying to execute.Gord Thompson
Edit your question to show us the revised Command8_Click() procedure with the Debug.Print strSQL statement in it.Gord Thompson
Okay, well, if executing the SQL statement (CurrentDb.Execute) causes an error that gets handled by errHandling: then the Debug.Print will never get executed, will it? Move the Debug.Print statement to immediately follow strSQL = "UPDATE ...".Gord Thompson
UPDATE tblReserve SET TableNum = D-02, CustomerID = 3, ResDate = '12/23/2013', ResTime = '10:00:00 PM' WHERE TableNum =D-02 this is what appeared in my immediate window after inputting data onto my form.nutellafella

2 Answers

2
votes

As revealed in our [chat][1], the essence of the problem was that [TableNum] is a text field and therefore its value had to be enclosed in quotes:

"... WHERE TableNum = '" & Me.TableNum & "'"

[1]: https://chat.stackoverflow.com/rooms/42746/discussion-between-nutellafella-and-gord-thompson)

0
votes

Try something like this

strSQL = "UPDATE tblReserve SET CustomerID = " & Me.txtCustID & _
", ResDate = " & "'" & Me.txtResDate & "'" & ", ResTime = " & "'" & Me.txtTime & "'" &  " WHERE TableNum =" & Me.TableNum

I am not sure why you have 2 sets of double quotes inside double quotes, I think what you were looking for is single quotes :)

However, there are much better ways to format sql than this. Also this seems like homework, so study up!