Group:  Microsoft Access ยป microsoft.public.access.formscoding
Thread: Modifying Command Button

Geek News

Modifying Command Button
yassoon 12/24/2008 5:50:01 PM
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
Re: Modifying Command Button
"Coderz" <jpabs78[ at ]gmail.com> 12/27/2008 4:35:43 AM
Hi,

You can do so by entering your code after On Error GoTo
Err_FindCompany_Click.

http://www.sourcecodester.com - Download free source code


"yassoon" <yassoon[ at ]discussions.microsoft.com> wrote in message
news:C39EB2E1-3646-4116-8F18-A9A329C8B0B0[ at ]microsoft.com...
[Quoted Text]
> 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

Re: Modifying Command Button
"Mike Painter" <mddotpainter[ at ]sbcglobal.net> 12/27/2008 5:43:27 AM
>> I'd like to add a command buttons so that each one is dedicated to
[Quoted Text]
>> Find in a
>> specific data field, eg a button to search for last name, another to
>> search
>> for company name.

Why would you want to use a button when a combobox will do this in a better
manner?


Re: Modifying Command Button
"Linq Adams via AccessMonster.com" <u28780[ at ]uwe> 12/27/2008 2:03:14 PM
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

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200812/1

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net