Another Search by Form

ppoole16

Registered User.
Local time
Today, 19:08
Joined
Aug 21, 2003
Messages
57
My apologies for asking a question that has been asked many times before on this site. I've tried the codes and downloaded examples, however I'm still just not getting it.

I have a form named Booking Sheet with fields [Last] and [First] among others. I would like to make a separate form to seach either or both of these fields. I would like a list/combo box response where the user could click on the correct record to bring up the form.

And unfortunately, I have very little VB experience so please be kind.
 
The code you need would look something like this:


Private Sub cmdSearch_Click()

Dim MyDatabase As Database
Dim MyQueryDef As QueryDef
Dim where As Variant

Set MyDatabase = CurrentDb()

If ObjectExists("Queries", "qryDynamic_QBF") = True Then
MyDatabase.QueryDefs.Delete "qryDynamic_QBF"
MyDatabase.QueryDefs.Refresh
End If

where = Null
where = where & " AND [Last]= '" + Me![Last] + "'"
where = where & " AND [First]= '" + Me![First] + "'"

Set MyQueryDef = MyDatabase.CreateQueryDef("qryDynamic_QBF", _
"Select * from orders " & (" where " + Mid(where, 6) & ";"))
DoCmd.OpenForm "Name offormtoopen", acViewnormal, "qryDynamic_QBF"
End Sub

if you're still having problems you can post up your db.
 

Users who are viewing this thread

Back
Top Bottom