Missing Operator

D

DS

I have this SQL statement that I keep getting a missing operator in
Query expression....it's on the EmailAddress field in Values.....
the value is [email protected]
Any help apprecited
Thanks
DS



Me.TxtEID = Nz(DMax("EMailID", "EMail"), 0) + 1

Dim EMailSQL As String
EMailSQL = "INSERT INTO EMail (EMailID,SendTo,EMailAddress,FoneNumber) " & _
"VALUES (" & Forms!EMailSend![TxtEID] & "," & Forms!EMailSend![SendTo] &
"," & Forms!EMailSend![EmailAddress] & "," &
Forms!EMailSend![FoneNumber] & ")"
DoCmd.RunSQL (EMailSQL)
 
D

Duane Hookom

I expect some of your fields are text. You need to delimit these with quotes
in your SQL statement. For instance if there was only the SendTo field it is
was text, this would be your SQL:

EMailSQL = "INSERT INTO EMail (SendTo) " & _
"VALUES (""" & Forms!EMailSend![SendTo] & """)"
DoCmd.RunSQL (EMailSQL)
 
J

John Vinson

I have this SQL statement that I keep getting a missing operator in
Query expression....it's on the EmailAddress field in Values.....
the value is [email protected]
Any help apprecited
Thanks
DS

Any Text field must be delimited by either ' or " in the VALUES
clause. Try:

Dim EMailSQL As String
EMailSQL = "INSERT INTO EMail " _
& "(EMailID,SendTo,EMailAddress,FoneNumber) " _
& "VALUES (" & Forms!EMailSend![TxtEID] & ", '" _
& Forms!EMailSend![SendTo] & "', '" _
& Forms!EMailSend![EmailAddress] & "', '" _
& Forms!EMailSend![FoneNumber] & "');"
DoCmd.RunSQL (EMailSQL)

The SQL string should end up looking like

INSERT INTO Email(EMailID,SendTo,EmailAddress,FoneNumber) VALUES
(3432,'[email protected]','[email protected]','(333)555-1212');

One question though: why the extra work of the VBA and query
execution, rather than just using a bound form?

John W. Vinson[MVP]
 
D

DS

John said:
I have this SQL statement that I keep getting a missing operator in
Query expression....it's on the EmailAddress field in Values.....
the value is [email protected]
Any help apprecited
Thanks
DS


Any Text field must be delimited by either ' or " in the VALUES
clause. Try:

Dim EMailSQL As String
EMailSQL = "INSERT INTO EMail " _
& "(EMailID,SendTo,EMailAddress,FoneNumber) " _
& "VALUES (" & Forms!EMailSend![TxtEID] & ", '" _
& Forms!EMailSend![SendTo] & "', '" _
& Forms!EMailSend![EmailAddress] & "', '" _
& Forms!EMailSend![FoneNumber] & "');"
DoCmd.RunSQL (EMailSQL)

The SQL string should end up looking like

INSERT INTO Email(EMailID,SendTo,EmailAddress,FoneNumber) VALUES
(3432,'[email protected]','[email protected]','(333)555-1212');

One question though: why the extra work of the VBA and query
execution, rather than just using a bound form?

John W. Vinson[MVP]
That works! Thank You.
DS
 
D

DS

Duane said:
I expect some of your fields are text. You need to delimit these with quotes
in your SQL statement. For instance if there was only the SendTo field it is
was text, this would be your SQL:

EMailSQL = "INSERT INTO EMail (SendTo) " & _
"VALUES (""" & Forms!EMailSend![SendTo] & """)"
DoCmd.RunSQL (EMailSQL)
Thanks Duane! That also works!
DS
 
Top