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 (e-mail address removed)
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 (e-mail address removed)
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,'(e-mail address removed)','(e-mail address removed)','(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 (e-mail address removed)
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,'(e-mail address removed)','(e-mail address removed)','(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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Missing Operator 3
Syntax error (missing operator) 4
[missing operator] 1
Complex If Statement 6
Syntax (Missing Operator) in Query Expr .... 2
SQL Date Problem 3
Not Updating 9
For Loop 6

Top