RunTime Error 3134

G

Guest

Hi,

I inserted a message box, and it worked. However, the code still didn't do
anything.

Douglas J. Steele said:
Is the code executing? If you look at the On Click property of the form,
does it say [Event Procedure]? If not, correct that. If it does, try putting
a breakpoint in your code to see whether it runs (or a message box)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


ajhome said:
Hello Douglas,

Thank you for your help. I have entered the code just as you have said.
However, it still doesn't work. I am not getting an error message, it
just
doesn't do anything. It acts as if the button doesn't have any coding
behind
it.
 
D

Douglas J. Steele

Try changing to:

Dim strSQL As String

strSQL = "INSERT INTO tblMovement " & _
"(EmpID, InsertDate, EffectiveDate, CurrentUser, " & _
"NewSupervisor, NewTitle, NewCenter) " & _
"VALUES (" & lstSelectEmp.Column(0) & ", " & _
Format(txtInsertDate, "\#yyyy\-mm\-dd\#") & _
"," & Format(txtEffectiveDate, "\#yyyy\-mm\-dd\#") & ", " & _
Chr$(34) & txtCurrent & Chr$(34) & ", " & _
Chr$(34) & cboNewSupervisor & Chr$(34) & ", " & _
Chr$(34) & cboNewTitle & Chr$(34) & ", " & _
Chr$(34) & cboNewCenter & Chr$(34) & ")"

Debug.Print strSQL

CurrentDb.Execute strSQL, dbFailOnError

When the code runs, go to the Immediate Window (Ctrl-G) and look at the SQL
string that was written there. Does it look correct? What happens if you
create a query, paste that same SQL into it and run it?

Does adding the dbFailOnError parameter cause any meaning error to be
raised?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


ajhome said:
Hi,

I inserted a message box, and it worked. However, the code still didn't
do
anything.

Douglas J. Steele said:
Is the code executing? If you look at the On Click property of the form,
does it say [Event Procedure]? If not, correct that. If it does, try
putting
a breakpoint in your code to see whether it runs (or a message box)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


ajhome said:
Hello Douglas,

Thank you for your help. I have entered the code just as you have
said.
However, it still doesn't work. I am not getting an error message, it
just
doesn't do anything. It acts as if the button doesn't have any coding
behind
it.

:

If they're text fields, you need quotes around them, just as you have
for
the CurrentUser field.

CurrentDb.Execute "INSERT INTO tblMovement " & _
"(EmpID, InsertDate, EffectiveDate, CurrentUser, " & _
"NewSupervisor, NewTitle, NewCenter) " & _
"VALUES (" & lstSelectEmp.Column(0) & ", " & _
Format(txtInsertDate, "\#yyyy\-mm\-dd\#") & _
"," & Format(txtEffectiveDate, "\#yyyy\-mm\-dd\#") & ", " & _
Chr$(34) & txtCurrent & Chr$(34) & ", " & _
Chr$(34) & cboNewSupervisor & Chr$(34) & ", " & _
Chr$(34) & cboNewTitle & Chr$(34) & ", " & _
Chr$(34) & cboNewCenter & Chr$(34) & ")"


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Hello,
Would someone please tell me what is wrong with this code:
CurrentDb.Execute "INSERT INTO tblMovement (EmpID, InsertDate,
EffectiveDate, CurrentUser, NewSupervisor, NewTitle, NewCenter) " &
_
"VALUES (" & lstSelectEmp.Column(0) & ", " & Format(txtInsertDate,
"\#yyyy\-mm\-dd\#") & _
"," & Format(txtEffectiveDate, "\#yyyy\-mm\-dd\#") & ", " &
Chr$(34)
&
txtCurrent & Chr$(34) & ", " & cboNewSupervisor & _
", " & cboNewTitle & ", " & cboNewCenter & ")"

The last 3 fields are text fields. When I put quotes around them,
it
gives
me an error message of too few fields.

Thanks,
AJ
 
G

Guest

Good Morning,

It tells me the following message:
"The INSERT INTO statement contains the following unknown field name:
'NewSupervisor'.

When I take that field out, I get the same error message for the other
fields as well. I have doubled checked my form and table to make sure that I
have spelled everything correctly and the same, and I have. What else could
be causing that error?
 
D

Douglas J. Steele

One possibility is your field CurrentUser: that's a reserved word, and so
can lead to problems. (For a great discussion on what names to avoid in
Access, see what Allen Browne has at
http://www.allenbrowne.com/AppIssueBadWord.html)

For now, try enclosing it in square brackets

strSQL = "INSERT INTO tblMovement " & _
"(EmpID, InsertDate, EffectiveDate, [CurrentUser], " & _
"NewSupervisor, NewTitle, NewCenter) " & _
etc

If that solves the issue, consider renaming the field (even though that's a
lot of work...)
 
G

Guest

I tried, and it still didn't work. I have also changed that field name to
logon.

Douglas J. Steele said:
One possibility is your field CurrentUser: that's a reserved word, and so
can lead to problems. (For a great discussion on what names to avoid in
Access, see what Allen Browne has at
http://www.allenbrowne.com/AppIssueBadWord.html)

For now, try enclosing it in square brackets

strSQL = "INSERT INTO tblMovement " & _
"(EmpID, InsertDate, EffectiveDate, [CurrentUser], " & _
"NewSupervisor, NewTitle, NewCenter) " & _
etc

If that solves the issue, consider renaming the field (even though that's a
lot of work...)


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


ajhome said:
Good Morning,

It tells me the following message:
"The INSERT INTO statement contains the following unknown field name:
'NewSupervisor'.

When I take that field out, I get the same error message for the other
fields as well. I have doubled checked my form and table to make sure
that I
have spelled everything correctly and the same, and I have. What else
could
be causing that error?
 
D

Douglas J. Steele

What are the fields in your tblMovement table?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


ajhome said:
I tried, and it still didn't work. I have also changed that field name to
logon.

Douglas J. Steele said:
One possibility is your field CurrentUser: that's a reserved word, and so
can lead to problems. (For a great discussion on what names to avoid in
Access, see what Allen Browne has at
http://www.allenbrowne.com/AppIssueBadWord.html)

For now, try enclosing it in square brackets

strSQL = "INSERT INTO tblMovement " & _
"(EmpID, InsertDate, EffectiveDate, [CurrentUser], " & _
"NewSupervisor, NewTitle, NewCenter) " & _
etc

If that solves the issue, consider renaming the field (even though that's
a
lot of work...)


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


ajhome said:
Good Morning,

It tells me the following message:
"The INSERT INTO statement contains the following unknown field name:
'NewSupervisor'.

When I take that field out, I get the same error message for the other
fields as well. I have doubled checked my form and table to make sure
that I
have spelled everything correctly and the same, and I have. What else
could
be causing that error?

:

Try changing to:

Dim strSQL As String

strSQL = "INSERT INTO tblMovement " & _
"(EmpID, InsertDate, EffectiveDate, CurrentUser, " & _
"NewSupervisor, NewTitle, NewCenter) " & _
"VALUES (" & lstSelectEmp.Column(0) & ", " & _
Format(txtInsertDate, "\#yyyy\-mm\-dd\#") & _
"," & Format(txtEffectiveDate, "\#yyyy\-mm\-dd\#") & ", " & _
Chr$(34) & txtCurrent & Chr$(34) & ", " & _
Chr$(34) & cboNewSupervisor & Chr$(34) & ", " & _
Chr$(34) & cboNewTitle & Chr$(34) & ", " & _
Chr$(34) & cboNewCenter & Chr$(34) & ")"

Debug.Print strSQL

CurrentDb.Execute strSQL, dbFailOnError

When the code runs, go to the Immediate Window (Ctrl-G) and look at
the
SQL
string that was written there. Does it look correct? What happens if
you
create a query, paste that same SQL into it and run it?

Does adding the dbFailOnError parameter cause any meaning error to be
raised?
 

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

Top