Modifying Command Button

Y

yassoon

I'd like to add a command buttons so that each one is dedicated to Find in a
specific data field, eg a button to search for last name, another to search
for company name. And so there'd be a macros for each button. How do I
modify the script so that it goes to a specific field? Below is the default
script. If someone could tell me what and where I need to add to the script,
that would be great. Thanks

MsgBox Err.Description
Resume Exit_FindName_Click

End Sub
Private Sub FindCompany_Click()
On Error GoTo Err_FindCompany_Click


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

Exit_FindCompany_Click:
Exit Sub

Err_FindCompany_Click:
MsgBox Err.Description
Resume Exit_FindCompany_Click

End Sub
 
M

Mike Painter

I'd like to add a command buttons so that each one is dedicated to
Why would you want to use a button when a combobox will do this in a better
manner?
 
L

Linq Adams via AccessMonster.com

Your code

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

is designed to allow you to use a single command button to search any field.
The line

Screen.PreviousControl.SetFocus

sends the focus to whichever field last held focus and then searches on that
field. So if you have the cursor in the Company field and click the button,
it'llsearch the Company field, if the cursor was in the LastName field, it'll
search that field.

To make each button search a specific field, you'd simply replace

Screen.PreviousControl.SetFocus

with

CompanyField.SetFocus

or

LastName.SetFocus
 

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

Top