Too few Paramets, expected 1 error

K

-Karl

This seems to be a common issue but I have yet to understand why my
code doesn't work. thanks for the extra help!


Maybe I just mistyped something here but this is what I am trying to
do:
1) Insert data into table A (This works)
2) Query table A for the value that was just inserted so I can get the
ID of the record (This is the problem)


Code:

'Insert the Site Name
DBStr = "INSERT INTO Sites (Site) VALUES ('" & Text2.Value
& "')"
CurrentDb.Execute DBStr, dbFailOnError


'Now get the ID of the Site that you just entered
Dim dbl As DAO.Database
Dim rsNewTest As DAO.Recordset
Set dbl = CurrentDb()

strSQL = "Select Site from Sites where Site=" & Text2.Value
Set rsNewTest = dbl.OpenRecordset(strSQL, dbOpenDynaset)
 
K

-Karl

Nevermind, I got ti finally. My DBStr was not properly made

'Now get the ID of the Site that you just entered

Dim dbl As DAO.Database
Dim rsNewTest As DAO.Recordset
Set dbl = CurrentDb()
DBStr = "Select ID, Site from Sites where Site='" &
Text2.Value & "'"
'MsgBox DBStr

Set rsNewTest = dbl.OpenRecordset(DBStr, dbOpenDynaset)

Do Until rsNewTest.EOF
MsgBox rsNewTest.Fields("ID") & " " &
rsNewTest.Fields("Site")
rsNewTest.MoveNext
Loop
 

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