Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with VBA code on a Search Form

Status
Not open for further replies.

AQHA

Technical User
Apr 5, 2007
7
US
I am needing help on fixing the following:

When I run this, I get
Compile error:
User-defined type not defined
Dim MyRS As DAO.Recordset is where it stops-----

Private Sub Exhibitor_Search_OK_Click()
On Error GoTo Exhibitor_Search_OK_Click_Err
Dim Criteria As String
Dim MyRS As DAO.Recordset

Set MyRS = Forms![Exhibitors].RecordsetClone
Criteria = "[LastName]=""" & Me![Select Exhibitor] & """"
MyRS.Find Criteria
If Not MyRS.NoMatch Then
Forms![Exhibitors].Bookmark = MyRS.Bookmark
End If
MyRS.Close
Set MyRS = Nothing

DoCmd.Close acForm, "Exhibitor Search"

Exhibitor_Search_OK_Click_Exit:
Exit Sub

Exhibitor_Search_OK_Click_Err:
MsgBox Err.Description
Resume Exhibitor_Search_OK_Click_Exit
End Sub


And When I run this, I get
"An expression you entered is the wrong data type for one of the arguments.
Private Sub Select_Exhibitor_DblClick(Cancel As Integer)
On Error GoTo Select_Exhibitor_DblClick_Err
DoCmd.SelectObject acForm, "Exhibitors"
DoCmd.GoToControl "LastName"
DoCmd.FindRecord Forms![Exhibitor Search]![Select Exhibitor], acEntire, False, acDown, False, acCurrent
DoCmd.Close acForm, "Exhibitor Search"

Select_Exhibitor_DblClick_Exit:
Exit Sub

Select_Exhibitor_DblClick_Err:
MsgBox Err.Description
Resume Select_Exhibitor_DblClick_Exit

End Sub
 
You need to set the reference to DAO. In the VBA window go to "tools", "references" and look for "Microsoft DAO 3.X Object Library". Click it.
 
OK, now I have "Microsoft DAO 3.X Object Library" in my references and the error message has disappeared, but it does not return the record that I have selected. What do I need to do next?
 
There is no method called just "find"
Code:
 MyRS.Find Criteria

it should be:
myRS.FindFirst Criteria
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top