Question : MS Access 2007 VBA SQL Debug INSERT, Error 3061 Too Few Parameters. Expected 1.

Run Time Error 3061 Too Few Parameters. Expected 1.
Code Snippet:
1:
2:
3:
4:
5:
Dim SqlStr As String
    Dim vusernumber As String
    vusernumber = Mid(UCase$(Environ$("Username")), 1, 7)
    SqlStr = "INSERT INTO OT_table ([OT_number], [date_open]) VALUES (vusernumber, #" & Date & "#);"
    CurrentDb.Execute SqlStr, dbFailOnError
Open in New Window Select All

Answer : MS Access 2007 VBA SQL Debug INSERT, Error 3061 Too Few Parameters. Expected 1.

vusernumber looks like a variable, not a field name.

The "too few parameters" error occurs when field names are unrecognized.  

You need to seperate variables outside of the SQL, and concatenate them using &'s.

If  vusernumber is numeric, use this:

    SqlStr = "INSERT INTO OT_table ([OT_number], [date_open]) VALUES (" & vusernumber & ", #" & Date & "#);"

If it is Text, use this:

    SqlStr = "INSERT INTO OT_table ([OT_number], [date_open]) VALUES ('" & vusernumber & "', #" & Date & "#);"

Random Solutions  
 
programming4us programming4us