execute

G

Guest

I am having an error code come up saying Run Time Error '3061' Too few
parameters. Expected 1

This error shows me my execute statement:
db.execute strSQL, dbFailOnError.

I have defined by db as CurrentDb already. I am trying to execute my Insert
Into statement which is the variable strSQL.
Please help anyone.....
 
D

Dirk Goldgar

amy14775 said:
I am having an error code come up saying Run Time Error '3061' Too few
parameters. Expected 1

This error shows me my execute statement:
db.execute strSQL, dbFailOnError.

I have defined by db as CurrentDb already. I am trying to execute my
Insert Into statement which is the variable strSQL.
Please help anyone.....

You'll get that message when the SQL string contains an unresolved
parameter, or an unrecognized word that the query engine construes as a
parameter. Does your SQL string contain a reference to a control on a
form? If so, DAO won't recognize it and fill it in automatically.
Usually, your best solution to this problem is to build the value of the
control into the string, rather than a reference to the control.

What's the value of strSQL, and what does the surrounding code look
like?
 
G

Guest

Dirk,
This is the code for the calculation button. I am trying to populate a table
with records that are calculated from this code. Basically it will loop
through and give me 12 dates in the future that will be seperate records in
my other table. The string is my Insert Into code. The values in the code
will partly be what the user enters on the form and part what the code
calculates for the dates needed in the future. But like I said previously, I
keep getting the parameter message. Any help you can give would be so greatly
appreciated. It is one of those I had to get up for a little while and walk
away. So a fresh set of eyes would be most helpful.
Thank you,
Amy



Private Sub cmdCalcWeek_Click()
Dim db As DAO.Database
Dim intCounter As Integer
Dim dteTest As Date
Dim dteStart As Date
Dim strSql As String

Set db = CurrentDb
dteStart = Me.txtStart

For intCounter = 1 To 12 Step 1
dteTest = DateAdd("d", 7, dteStart)
strSql = "Insert Into Test(SocialSecurity,StartDate,TestType,DateDue)" &
"Values('" & Me.txtSocialSecurity & "', #" & Me.txtStart & "#, " &
Me.lstTestType & ", #" & dteTest & "#)"

db.Execute strSql, [dbFailOnError]
dteStart = dteTest
Next intCounter

Set db = Nothing
 
D

Dirk Goldgar

amy14775 said:
Dirk,
This is the code for the calculation button. I am trying to populate
a table with records that are calculated from this code. Basically it
will loop through and give me 12 dates in the future that will be
seperate records in my other table. The string is my Insert Into
code. The values in the code will partly be what the user enters on
the form and part what the code calculates for the dates needed in
the future. But like I said previously, I keep getting the parameter
message. Any help you can give would be so greatly appreciated. It is
one of those I had to get up for a little while and walk away. So a
fresh set of eyes would be most helpful.
Thank you,
Amy



Private Sub cmdCalcWeek_Click()
Dim db As DAO.Database
Dim intCounter As Integer
Dim dteTest As Date
Dim dteStart As Date
Dim strSql As String

Set db = CurrentDb
dteStart = Me.txtStart

For intCounter = 1 To 12 Step 1
dteTest = DateAdd("d", 7, dteStart)
strSql = "Insert Into
Test(SocialSecurity,StartDate,TestType,DateDue)" & "Values('" &
Me.txtSocialSecurity & "', #" & Me.txtStart & "#, " & Me.lstTestType
& ", #" & dteTest & "#)"

db.Execute strSql, [dbFailOnError]
dteStart = dteTest
Next intCounter

Set db = Nothing

Make sure that "Test" is really the name of your table, and that
"SocialSecurity", "StartDate", "TestType", and "DateDue" are really the
names of fields in that table -- check the exact spellings. Also, check
that TestType is a numeric field, and that the bound column of
lstTestType contains numeric values.

If I were writing this, I'd put a space into the SQL string before the
"Values" keyword for clarity, but that isn't actually required in this
case because the closing parenthesis is a sufficient delimiter.
 
G

Guest

The names are all correct. But the TestType field is a text field with the
name of the test needed in it. The same goes for the list boxes. Is this what
is causing the problem?If so do you know the direction I need to go to fix
it. I appreciate all the time and help.

Dirk Goldgar said:
amy14775 said:
Dirk,
This is the code for the calculation button. I am trying to populate
a table with records that are calculated from this code. Basically it
will loop through and give me 12 dates in the future that will be
seperate records in my other table. The string is my Insert Into
code. The values in the code will partly be what the user enters on
the form and part what the code calculates for the dates needed in
the future. But like I said previously, I keep getting the parameter
message. Any help you can give would be so greatly appreciated. It is
one of those I had to get up for a little while and walk away. So a
fresh set of eyes would be most helpful.
Thank you,
Amy



Private Sub cmdCalcWeek_Click()
Dim db As DAO.Database
Dim intCounter As Integer
Dim dteTest As Date
Dim dteStart As Date
Dim strSql As String

Set db = CurrentDb
dteStart = Me.txtStart

For intCounter = 1 To 12 Step 1
dteTest = DateAdd("d", 7, dteStart)
strSql = "Insert Into
Test(SocialSecurity,StartDate,TestType,DateDue)" & "Values('" &
Me.txtSocialSecurity & "', #" & Me.txtStart & "#, " & Me.lstTestType
& ", #" & dteTest & "#)"

db.Execute strSql, [dbFailOnError]
dteStart = dteTest
Next intCounter

Set db = Nothing

Make sure that "Test" is really the name of your table, and that
"SocialSecurity", "StartDate", "TestType", and "DateDue" are really the
names of fields in that table -- check the exact spellings. Also, check
that TestType is a numeric field, and that the bound column of
lstTestType contains numeric values.

If I were writing this, I'd put a space into the SQL string before the
"Values" keyword for clarity, but that isn't actually required in this
case because the closing parenthesis is a sufficient delimiter.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
D

Dirk Goldgar

amy14775 said:
The names are all correct. But the TestType field is a text field
with the name of the test needed in it. The same goes for the list
boxes. Is this what is causing the problem?

I think so.
If so do you know the
direction I need to go to fix it.

Try this:

strSql = _
"Insert Into Test " & _
"(SocialSecurity,StartDate,TestType,DateDue) " & _
"Values ('" & _
Me.txtSocialSecurity & "', #" & _
Format(Me.txtStart, "mm/dd/yyyy") & "#, '" & _
Me.lstTestType & "', #" & _
Format(dteTest, "mm/dd/yyyy") & "#)"

That should work, provide the values for TestType can't contain the
single-quote character ('). I also took the liberty of forcing the
format of your date fields to mm/dd/yyyy, to prevent any chance of
misinterpretation of ambiguous dates.
 
G

Guest

OH GREAT GURU, I AM NOT WORTHY....It works great. Thank you so much. I could
not figure out for the life of me to figure out where I was missing it. Thank
you sooooooo much. I almost cried I was so happy.
Thank you
 

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