Find Record Code

L

Linda RQ

Hi Everyone,

Using Access 2003. I added a comand button to my form and used the wizard.
This works fine in opening up the Find window but I would like the default
settings to be

--Look In: "Last Name" (This is the default because my focus is in this
control at the time the window pops up. I am confused because "Last Name"
is the name of the label, the name of the control is PtLName)

--Match: Start of field (Default is Whole Field)

--Search: All (This is the Default)


Below is the code behind the button right now and I don't see anything in
there about how the window opens up. Is this even possible to do?
Thanks,
Linda


Private Sub cmdFindRecord_Click()
On Error GoTo Err_cmdFindRecord_Click


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

Exit_cmdFindRecord_Click:
Exit Sub

Err_cmdFindRecord_Click:
MsgBox Err.Description
Resume Exit_cmdFindRecord_Click

End Sub
 
K

Klatuu

Wizards are some of the worst coders in the world. If you want find a
specific record and make it the current record, Something like this will work
a lot better:

Instead of button to open a find window, use a Combo box control with a
query as the row source that includes the LastName field of the form's record
source. Then in the AfterUpdate event of the combo:

With Me.RecordsetClone
.FindFirst "[Last Name] = '" & Me.MyCombo & "'"
If .NoMatch Then
MsgBox "Last Name Not Found"
Else
Me.BookMark = .BookMark
End If
End With

Change [Last Name] to the name of the field in the form's record source you
want to match on
ChangeMyCombo to the name of the combo box.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top