Error 3061: Too Few Parameters. Expected 1 Problem:

gold007eye

Registered User.
Local time
Today, 15:14
Joined
May 11, 2005
Messages
260
Could anyone tell me what I am doing wrong here. I read through several posts and tried using the solutions, but to no avail. Here is the code I am using:

Code:
            Dim db As DAO.Database
            Dim MySQL As String
            Set db = CurrentDb()
            MySQL = "INSERT INTO [Transaction Codes]([Transaction Code]) VALUES (" & NewData & ");"
            db.Execute MySQL, dbFailOnError
            Set db = Nothing

Although I am getting the error when I put my mouse over the "MySQL" line in the debug window the "Values" are showing the correct text. I just don't understand what it means by "Expected 1"

If it helps the Transaction Codes table has 2 fields; "Transaction Code" (Text)& "Status" (On/Off)
 
Try changing this:
VALUES (" & NewData & ");"

To this:

VALUES ('" & NewData & "');"
 
SQL doesnt have the brackets round the items to be inserted

insert into tblname (fields1, field2) values value1, value2

so I would lose the brackets round the value list

-------
one other point

you need

on error goto a_fail_label

to set up the error hanlder BEFORE your execute statement - if you have an active error handler elsewhere in your code, you may find you transfer program execution to the wrong place by mistake
 
you need

on error goto a_fail_label

to set up the error hanlder BEFORE your execute statement - if you have an active error handler elsewhere in your code, you may find you transfer program execution to the wrong place by mistake

So this would be like

On_NotInList GoTo NotInList_Err

type code? What exactly am I going to try and capture with the code? Any examples I can work from? Thanks.
 
Try changing this:
VALUES (" & NewData & ");"

To this:

VALUES ('" & NewData & "');"


PERFECT! :) That did the trick. Now I just need to figure out how to requery the "Transaction Code" field on the form w/out getting the 2118 Error. "You must save the current field before you run the Requery action." :\
 
in your code, you need to handle an error, somewhat as follows
enable the error handler before the execute system

if there is an error, the code jumps to the error handler, then you need ot close the error handler with a resume statement.

Otherwise an error will just crash your program completely

Code:
sub doit
           
Dim db As DAO.Database
Dim MySQL As String
            Set db = CurrentDb()
            MySQL = "INSERT INTO [Transaction Codes]([Transaction Code])VALUES (" & NewData & ");"
          [COLOR="Red"] on error goto fail[/COLOR]
            db.Execute MySQL, dbFailOnError

[COLOR="red"]exithere:
            Set db = Nothing            
            exit sub

fail:
msgbox("Insert failed")
resume exithere[/COLOR]

end sub
 

Users who are viewing this thread

Back
Top Bottom