Dee wrote:
Running an AfterUpdate event procedure, I get the following error:
"Too few parameters. Expected 1."
My code is as follows:
Private Sub DealerID_AfterU pdate()
Dim db As DAO.Database
Dim qd As DAO.QueryDef
Dim rs As DAO.Recordset
Set db = CurrentDb
Set qd = db.QueryDefs("Q rCheckDlrAssign ed")
Set rs = qd.OpenRecordse t()
If Not rs.EOF Then
Me!Terassigned = rs!Dlr_assigned
End If
On Error Resume Next
Set rs = Nothing
Set qd = Nothing
Set db = Nothing
End Sub
The query returns only one field from one record of a table with 150
records. The field is a yes/no check field.
The query is a select query called "QrCheckDlrAssi gned".
The field colums is name is "Dlr assigned".
I'm sort of a newbie and have a little problem understanding some of
the terms a read in other posts. Still don't know what DAO, stands
for.
I had this problem just 2 days ago. Exactly the same situation. Check
the query QrCheckDlrAssig ned and there will be a criteria referring to
another field or form field ([forms]![myform]![id_field]). In my case
the query I was referring to had no criteria but the query it was based
on had a criteria. I had to delete the parameter 2 queries deep and it
ran straight away. I was really confused as the query would run normally.
Just try removing the criteria in the criteria and seeing if the code runs.
I have used some workarounds to eliminate this problem in the past. Let
me know and I will send them if you want. It involves reading the query
SQL into a string and adding the criteria by string manipulation.
If the query is used for nothing else you could put a token in the
criteria, say 123456, and then replace that token with the value you
have stored in a VBA variable. Have a look at
http://www.mvps.org/access
in the Strings section for the Find and Replace function. Very useful.
Pass in three variables, the string being searched, the value to be
replaced and the value to replace it with.
HTH
Gavin