Results 1 to 10 of 10
  1. #1
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    Florida, USA
    Posts
    394
    Thanks
    0
    Thanked 0 Times in 0 Posts

    FindRecord Control Button (Office 2000)

    Hello,
    I have a Control Button on a form to Find a Record [FindRecord]. It actually does the same thing that the toolbar button does.

    What I wanted to do is have the control always look in the same field instead of where ever I happen to be at the time. I have to keep remembering to click on the field I want before I click on the Find button.

    Can this be done?
    Thanks!
    Louise

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: FindRecord Control Button (Office 2000)

    Open the form in design view.
    Select the command button.
    Activate the Event tab of the Properties window.
    Click in the On Click event, then click the ... button to the right of the dropdown arrow.
    Make the code look like this, where cmdFind is the name of the command button and ControlName is the name of the control bound to the field in which you want to search:

    Private Sub Knop24_Click()
    Me![NameOfControl].SetFocus
    RunCommand acCmdFind
    End Sub

  3. #3
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    Florida, USA
    Posts
    394
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FindRecord Control Button (Office 2000)

    Hi Hans,
    Thanks for your reply. This is what the code is currently:

    Private Sub FindRecord_Click()
    On Error GoTo Err_FindRecord_Click


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

    Exit_FindRecord_Click:
    Exit Sub

    Err_FindRecord_Click:
    MsgBox Err.Description
    Resume Exit_FindRecord_Click

    End Sub


    Do I replace any of it with yours? or do I just insert it somewhere with the modifications?

    Thanks
    Louise

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: FindRecord Control Button (Office 2000)

    You only need to replace Screen.PreviousControl with the name of the control bound to the field in which you want to search.

  5. #5
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    Florida, USA
    Posts
    394
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FindRecord Control Button (Office 2000)

    Perfect! Thank you so much!
    Louise

  6. #6
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    Florida, USA
    Posts
    394
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FindRecord Control Button (Office 2000)

    Hi Hans,
    I decided to create another command button which would find records using the account number. This way I would have a choice between LastName or AccountNumber. As I did previously, I replaced the "Screen.PreviousControl " with the "AccountNumber" but get a Compile error message. Says that "Method or data member not found" and the ".set focus" is highlighted.

    This is the entire code:
    Private Sub FindRecord_by_Acct_Number_Click()
    On Error GoTo Err_FindRecord_by_Acct_Number_Click


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

    Exit_FindRecord_by_Acct_Number_Click:
    Exit Sub

    Err_FindRecord_by_Acct_Number_Click:
    MsgBox Err.Description
    Resume Exit_FindRecord_by_Acct_Number_Click

    End Sub

    I don't understand what I did wrong.

    Thanks,
    Louise

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: FindRecord Control Button (Office 2000)

    With the form in design view, select the control (text box or whatever) bound to the account number field. Then look at the Other tab of the Properties window. What is the exact name of the control?

  8. #8
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    Florida, USA
    Posts
    394
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FindRecord Control Button (Office 2000)

    Hi Hans,
    Ok, the exact name as it appears in the Properties window is Account Number. I see that there is a space in between Account and Number. I tried substituting (or adding a space in between) and it still doesn't work.

    Thanks,
    Louise

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: FindRecord Control Button (Office 2000)

    You can use either

    [Account Number].SetFocus

    or

    Account_Number.SetFocus

    (This is one of the reasons I never use spaces and unusual symbols in the names of fields, controls and database objects - you have to do extra work to deal with such names)

  10. #10
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    Florida, USA
    Posts
    394
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FindRecord Control Button (Office 2000)

    Hi Hans,

    I guess I'm learning what not to do! <img src=/S/blush.gif border=0 alt=blush width=15 height=15> The Account_Number.SetFocus works.

    Thanks once again,
    Louise

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •