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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search Function Help 1

Status
Not open for further replies.

soahc00

Technical User
Oct 25, 2004
14
US
Hey guys, I have a form, and a command button. The command button opens the standard find dialog box. I want it to go to the first record, and then it searches the last name record field in the form, and when it finds it go to that form record (I don't want it to go to the actual db, I want it to work from the forms). Right now when i click the button I get an error that says....

The control 'lastnamesearch' the macro is attempting to search can't be searched.


Try one of the following:
Add a GoToControl action before the FindRecord action.

For the FindRecord action, change the Only Current Field action argument from Yes to No.

Change the focus to a searchable controls.


But I'm a n00b and I'm not sure what to do.... here is my code for that function..

Code:
Private Sub lastnamesearch__Click()
On Error GoTo Err_lastnamesearch__Click

    DoCmd.GoToRecord , , acFirst
    Screen.PreviousControl.SetFocus
    DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70

Exit_lastnamesearch__Click:
    Exit Sub

Err_lastnamesearch__Click:
    MsgBox Err.Description
    Resume Exit_lastnamesearch__Click
    
End Sub
 
I'm not sure that's the best way to handle it. Basically, you're moving the user off the current record just to find something. You might try putting a combobox on the form from which the user can select the item they want to find (or you could have them enter the info in a "find" textbox). Either way, in the AfterUpdate event of the control (i.e. combobox), enter something like this:

Me.RecordsetClone.FindFirst "LastName = '" & cboBox.Value & "'"
If (Me.RecordsetClone.EOF) Then
MsgBox "no match"
Else
Me.Recordset.Bookmark = Me.RecordsetClone.Bookmark
End If
 
ok well lets say I did want to do it that way, how can I fix it?

This is mostly because I like the way it would work and because I don't know how to apply your code. I get a runtime error 7951 that say I entered an expressio taht has an invalid reference to the recordsetclone property

thanks in advance...

Mark
 
Sorry, I didn't mean to say that you shouldn't use the FindDialog Box. Just that I wouldn't leave the current record. Also, just wanted to show you another way of doing it.

To use the FindDialog box, first setfocus to the field you want the user to search on (i.e. LastName) and then issue the DoMenuItem call. Like this:
Code:
Private Sub lastnamesearch__Click()
On Error GoTo Err_lastnamesearch__Click

    LastName.SetFocus
    DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70

Exit_lastnamesearch__Click:
    Exit Sub

Err_lastnamesearch__Click:
    MsgBox Err.Description
    Resume Exit_lastnamesearch__Click
    
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top