Dirk, Hi. Yes. I created a form and on it I ask for the employee No I'm
looking for. The "employee No" is the Primary Key so It will only select 1
record. I created the query using the design view and reference the "text
box" in the command button someone will press to start the query.
Thanks!
> > Dirk, Hi. I'm over my head but I entered the code. I understand it
> > but I get an error about too few Parameters expected 1. I am reading
> > help but don't understand. Help!!
>
> What's the SQL of the query? Does it make reference to a control on a
> form, as a criterion perhaps?
> Dirk, Hi. Yes. I created a form and on it I ask for the employee No
> I'm looking for. The "employee No" is the Primary Key so It will
> only select 1 record. I created the query using the design view and
> reference the "text box" in the command button someone will press to
> start the query.
You didn't actually answer my question about the SQL of the query, but
I'm going to guess that it does use a parameter reference to the text
box on your form. The trouble is that, while *Access* understands such
references and can fill them in automatically, when you use DAO to open
a recordset, Access isn't really involved in the process and won't fill
in the value of that parameter. So you have to do it yourself. Since
you didn't post the SQL so I could see what the name of the form and
control are, I'll show you how to open a recordset in such a way that it
doesn't matter what the names are. Try this, or something like it:
Dim strEmployeeID As String
Dim dtHireDate As Date
Dim strDepartment As String
Dim strTitle As String
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim rs As DAO.Recordset
Dim prm As DAO.Parameter
Set db = Application.DBEngine(0)(0)
Set qdf = db.QueryDefs("YourQueryName")
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set rs = qdf.OpenRecordset
With rs
If .EOF Then
MsgBox "No records in query! Something's wrong."
Else
strEmployeeID = !EmployeeID
dtHireDate = !HireDate
strDepartment = !Department
strTitle = !Title
End If
.Close
End With
Set rs = Nothing
Set qdf = Nothing
Set db = Nothing

Signature
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)
williamr - 10 Apr 2006 22:21 GMT
Dirk, Hi. I followed your instructions and it works! I think! I'm having
trouble with some fields being 'null' but for the most pary it owrks. Thank
you.
Wm.
> > Dirk, Hi. Yes. I created a form and on it I ask for the employee No
> > I'm looking for. The "employee No" is the Primary Key so It will
[quoted text clipped - 46 lines]
> Set qdf = Nothing
> Set db = Nothing
Dirk Goldgar - 10 Apr 2006 23:40 GMT
> Dirk, Hi. I followed your instructions and it works! I think! I'm
> having trouble with some fields being 'null' but for the most pary it
> owrks. Thank you.
You're welcome. I suggest you post a followup question about these Null
fields as the start of a new discussion thread.

Signature
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)