"Too Few Paramters"?

N

nazir.atif

What's wrong with this? It gives me: "Too few parameters. Expected 1."
and the debugger points to the currentDB.Execute(query)
-- snip --


CodeBox.SetFocus
code = Str(CodeBox.Text)
DescBox.SetFocus
desc = DescBox.Text

query = "INSERT INTO ExpCode(Code, Description) VALUES(" + code + "," +
desc + ");"

MsgBox query

CurrentDb.Execute (query)

-- snip --
 
W

Wayne Morgan

What happens if you remove the parentheses from around "query"?

CurrentDb.Execute query

Also, you are using the plus sign for concatenation. This will work in most
cases, but can cause problems. Try using the ampersand (&) instead unless
you are using the + for a "special effect". There are times that the + does
have an advantage, but it is when doing more than just concatenating.
 
D

Duane Hookom

What do you see in the msgbox? You can use debug.Print query so your query
is printed in the immediate window.

You don't need to SetFocus. Just use the Value property (or even omit the
..Value or .Text).

I expect your issue is that your code might work if both fields were
numeric. Assuming they are both text, try:

code = Str(Me.CodeBox)
desc = Me.DescBox
query = "INSERT INTO ExpCode(Code, Description) " & _
"VALUES(""" & code & """,""" & desc & """);"

MsgBox query
Debug.Print query
CurrentDb.Execute query
 

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