DAO Database execute get too few parameter

S

Souris

I have one statment as following

Dim Db As DAO.Database
dim strMySQL as String

Set Db = CurrentDb
strMySQL = "INSERT INTO MyTable (MyField) values ("Hello")

db.execute strMySQL, dbFailOnError


but I got "too fewer parameters. Expected 1"

Any idea about this?

Your hjelp is great appreciated,
 
S

Stefan Hoffmann

hi,
strMySQL = "INSERT INTO MyTable (MyField) values ("Hello")
db.execute strMySQL, dbFailOnError
but I got "too fewer parameters. Expected 1"
This indicates normally a typo. Check the spellings of your table name
and the field names.


mfG
--> stefan <--
 
S

Souris

It works if I use DoCmd.RunSQL strMySQL.
The SQL is correct, but it fails when I use DAO database execute.

Does db.execute accept paramter like MyDropDown.value as a value in the
strMySQL?

The dropdown.value works for DoCmd.RunSQL.


Thanks again,
 
S

Stefan Hoffmann

hi,
It works if I use DoCmd.RunSQL strMySQL.
The SQL is correct, but it fails when I use DAO database execute.
Strange, but I'm sure i've seen it now...
Does db.execute accept paramter like MyDropDown.value as a value in the
strMySQL?

Dim db As DAO.Database
Dim strSQL as String
Dim strValue As String

strValue = Replace(MyDropDown.Value, "'", "''")
strSQL = "INSERT INTO MyTable (MyField) values ('" & strValue & "')

Set db = CurrentDb
db.Execute strSQL
Set db = Nothing


mfG
--> stefan <--
 
D

Douglas J. Steele

Your SQL string is incorrect. It should be:

strMySQL = "INSERT INTO MyTable (MyField) values ('Hello')"
 

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