RunTime Error 3134

G

Guest

Greetings...

Could someone tell me what is wrong with this line of code?

CurrentDb.Execute "INSERT INTO tblExistCheckList (EmpID, SupervisorID,
ADID,)" & _
"VALUES (" & lstSelectEmp.Column(0) & ", " &
lstSelectEmp.Column(2) & ", " & lstSelectEmp.Column(4) & ")"

All of the ID fields are text fields.
 
G

Guest

OK! Nevermind! I figured out I had an extra comma. However, I still need
help. I have a form that is populating a table. The code below is suppose
to add those 3 fields and the others in on the form. However, it is adding
the 3 fields from the code as a new record instead of with the other fields
on the form. Any suggestions?

Thanks,
AJ
 
D

Douglas J. Steele

You've got a comma between ADID and the closing parenthesis. As well, since
the ID fields are text, you must put quotes around the values:

CurrentDb.Execute "INSERT INTO tblExistCheckList (EmpID, SupervisorID,
ADID) " & _
"VALUES ('" & lstSelectEmp.Column(0) & "', '" & lstSelectEmp.Column(2) &
"', '" & lstSelectEmp.Column(4) & "')"

Exagerated for clarity, that's

CurrentDb.Execute "INSERT INTO tblExistCheckList (EmpID, SupervisorID,
ADID) " & _
"VALUES ( ' " & lstSelectEmp.Column(0) & " ' , ' " &
lstSelectEmp.Column(2) & " ', ' " & lstSelectEmp.Column(4) & " ' )"

(apologies in advance for the line wrapping.)
 
G

Guest

Thanks! Maybe you could help me with my other problem! I have an unbound
form with a bound subform. When I try to insert fields into the current
record of the subform, it adds the fields as new records instead of the
current. How do I insert data into the current record?

Thanks,
AJ
 
D

Douglas J. Steele

Realistically, it makes no sense to have a bound subform and an unbound
form. Subforms must be linked to the parent form, and you can't link unbound
forms.
 
J

John W. Vinson

Realistically, it makes no sense to have a bound subform and an unbound
form. Subforms must be linked to the parent form, and you can't link unbound
forms.

Well, I hate to disagree Douglas, but this is actually a pretty handy
technique for lots of things. You CAN link a bound subform to a control in an
unbound mainform; you need to use the *control name* - not a fieldname - as
the Master Link field. It can be a handy way to give a quick filtered form.

John W. Vinson [MVP]
 
G

Guest

Thank you both for your input! As part of the same form, I have an option
group (check boxes.) How do I insert whatever value my user selects into my
table?

Thanks,
AJ
 
J

John W. Vinson

Thank you both for your input! As part of the same form, I have an option
group (check boxes.) How do I insert whatever value my user selects into my
table?

An Option Group control has a single numeric value indicating which choice the
user made. What do you want inserted in your table? That number? A text string
based on the choice? or what?

John W. Vinson [MVP]
 
G

Guest

Good Morning,

I want to be able to insert the number or a text string based on the choice
made.

Thanks,
Alfia
 
J

John W. Vinson

Good Morning,

I want to be able to insert the number or a text string based on the choice
made.

Well... WHICH? Where do you want to insert it?

If you bind the option Group control to a number field, it will store the
selected number.

John W. Vinson [MVP]
 
G

Guest

Good Morning,

I tried to bind it to a number field, but it gives me an error stating that
"control can't be edited; it's bound to the expression..." How can I insert
the value as a text string based on the choice the user makes?

Thanks,
Aj
 
G

Guest

This is the code I am using (from "The Access Web" to return strings:
Sub ctlOption_AfterUpdate()
Select Case me!ctlOption
Case 1:
Msgbox "One was Selected"
Case 2:
Msgbox "Two was selected"

End Select
End sub

How do I insert one of those strings into the field, resignorterm in my
employee table?

Thanks,
Aj
 
D

Douglas J. Steele

Assuming resignorterm is a text field in the underlying recordset of the
form, try:

Sub ctlOption_AfterUpdate()
Select Case me!ctlOption
Case 1:
Me.resignorterm = "Text for option 1"
Case 2:
Me.resignorterm = "Text for option 2"
End Select
End sub



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)
 
G

Guest

Would someone please tell me what is wrong with this code:

CurrentDb.Execute "INSERT INTO tblMovement (EmpID, SupervisorID,
CurrentSupervisorID, CurrentADID, ADID, InsertDate, EffectiveDate, User) " & _
"VALUES (" & lstSelectEmp.Column(0) & ", " &
cboNewSupervisor.Column(0) & ", " & cboCurrentSupervisor.Column(0) & ", " &
cboCurrentSupervisor.Column(2) & ", " & cboNewSupervisor.Column(2) & ", " &
Format(txtInsertDate, "\#yyyy\-mm\-dd\#") & _
"," & Format(txtEffectiveDate, "\#yyyy\-mm\-dd\#") & ",
" & txtUser & ")"


I get an error message stating "too few parameters. Expected 1"
 
D

Douglas J. Steele

You asked this yesterday in a thread called "Run Time Error (again!)", and I
answered you then. Please don't start new threads when the previous ones are
still active!

To save you the effort of looking for the answer I gave you yesterday, here
it is again:

<RepeatAnswer>

Is User a text field? If so, you need quotes around the value you're
inserting. As well, User is a bad choice for a field name: it's a reserved
word, and using reserved words for your own purposes can lead to problems.
If you cannot (or will not) change the name, at least put square brackets
around it.

CurrentDb.Execute "INSERT INTO tblMovement (EmpID, SupervisorID,
CurrentSupervisorID, CurrentADID, ADID, InsertDate, EffectiveDate, User) " &
_
"VALUES (" & lstSelectEmp.Column(0) & ", " & _
cboNewSupervisor.Column(0) & ", " & _
cboCurrentSupervisor.Column(0) & ", " & _
cboCurrentSupervisor.Column(2) & ", " & _
cboNewSupervisor.Column(2) & ", " & _
Format(txtInsertDate, "\#yyyy\-mm\-dd\#") & _
"," & Format(txtEffectiveDate, "\#yyyy\-mm\-dd\#") & _
", " & Chr$(34) & txtUser & Chr$(34) & ")"

(I'm assuming the ID fields are all numeric. If not, you'll need quotes
there too)

For a good discussion of what names to avoid, see what Allen Browne has at
http://www.allenbrowne.com/AppIssueBadWord.html

</RepeatAnswer>
 
G

Guest

Please forgive me. I completely forgot about that thread. Thank you for all
of your help.

Aj
 
G

Guest

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
 
D

Douglas J. Steele

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) & ")"
 
G

Guest

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

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)
 

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