Syntax error - Missing Operator

Gavx

Registered User.
Local time
Tomorrow, 07:28
Joined
Mar 8, 2014
Messages
155
Running this code I get the error message about there being a missing operator

Code:
iCounter = 1
    Do Until iCounter = strResponse + 1
    Dim strClonedGuest As String
    strClonedGuest = strCloneGuestName & "(" & iCounter & ")"
    
Dim strSQL As String
strSQL = " INSERT INTO tblGuest (BookingID,GuestName) " _
              & " VALUES " me.txtBookingID,strClonedGuest;

  DoCmd.RunSQL strSQL
        iCounter = iCounter + 1
    Loop

I have pasted the output into a query window but that doesn't help.
Could it have something to do with the fact that strClonedGuest derives a value that looks like My Name(x) where x is a number.
 
Have found the source of the problem.
In another procedure the following code runs in relation to strCloneGuest;
Code:
      fName = StrConv(Left(Me.txtGuestName, InStr(1, Me.txtGuestName, " ") - 1), vbProperCase)
  
    lName = StrConv(Right(Trim(Me.txtGuestName), Len(Trim(Me.txtGuestName)) - InStr(1, Me.txtGuestName, " ")), vbUpperCase)
Which fails because of the "(x)" component of the string
 
Well, the code in the second post doesn't appear to be related to the first. The first would fail because you don't concatenate the values into the string, plus you don't include parentheses around the VALUES clause.
 
I would have expected strResponse to be defined as a string, which would give an error.

Also your sql is incorrect. If you had printed the run time value into the immediate window it definitely would show up the error.

Use something like
.....& " VALUES (" & me.txtBookingID & ", '" & strClonedGuest & "')"

What is it you are trying to achieve? Seems funny to me to insert guest records like
17 John Doe(1)
17 John Doe(2)
17 John Doe(3)
etc

Or are these meant to be the others associated with John Doe?
 
Last edited:
Also your sql is incorrect. If you had printed the run time value into the immediate window it definitely would show up the error.

Use something like
.....& " VALUES " & me.txtBookingID & ", '" & strClonedGuest & "'"

I already mentioned the values needed to be concatenated into the string, and your SQL is also incorrect.
 
Funny, I thought I had edited that post to put the brackets in. I normally use select instead of values.

So it should be

.....& " VALUES (" & me.txtBookingID & ", '" & strClonedGuest & "')"
or

.....& " select " & me.txtBookingID & ", '" & strClonedGuest & "'"
 

Users who are viewing this thread

Back
Top Bottom