I get runtime "error 3061": Too few paramenters. Expected 1.
The program was working fine until I added 9 new records in an Access table and tried to run VBA. I've checked that the new records have similar formatting as the existing set. Help!
Here's my code:
Set db = OpenDatabase("C:\Documents and Settings\test.mdb")
Set rs = db.OpenRecordset("SELECT * FROM newfile WHERE FieldName = '" %26amp; Name %26amp; "' AND Date=#" %26amp; FinDate %26amp; "#", dbReadOnly)
HELP! VBA/Access Error: Too few parameters. Expected 1.?
Very likely, what you're putting into Name contains single quotes and is breaking the sql.
change to
"SELECT * FROM newfile WHERE FieldName = '" %26amp; replace(Name, chr(39), chr(39) %26amp; chr(39) ) %26amp; "' AND Date=#" %26amp; FinDate %26amp; "#"
Reply:this usually means your sql is malformed.
put brackets about [fieldName] and [date] like that.
these are probably reserved words and using brackets should allow you to use them for your fieldnames.
Reply:Try SELECT * FROM newfile
If that works start putting in your WHERE statement in small amounts until your code breaks, then you'll know what part is throwing the error.
Reply:Or name and date are both blank.
Reply:Did that SQL work before you added records? Try removing all select (WHERE) criteria (just say Select * FROM newfile) and check the results, then begin adding WHERE clauses back in one at a time until you find the one at fault.
narcissus
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment