Results 1 to 12 of 12
  1. #1
    2 Star Lounger
    Join Date
    May 2002
    Location
    Jerusalem, Israel
    Posts
    187
    Thanks
    0
    Thanked 0 Times in 0 Posts

    GoToControl (Access 2000)

    I have a search form in my database where you can select the "order number" from a combo box, or type in the order number yourself. To activate the search you have to click the "search" button.

    I would like to make it so that all you have to do is press "Enter" on the keyboard to activate the search.

    I tried doing this using a macro which is the GoToControl function applied to the "After Update" property in Events. It takes you to the search button, but doesn't activate the search. You need to press "Enter" twice on your keyboard (one to give the search button focus and the other to activate the search button) . While I know that it is not a big deal to press the enter key twice, I was wondering if there is a built in macro function that will automatically activate the search code so that you only have to press the enter key once. I looked through the list of options in "RunCommand" but did not come across anything that worked.

    Any ideas?

    Thanks,

    JoeK

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

    Re: GoToControl (Access 2000)

    Why don't you put the search code in the After Update event of the combo box instead of in the On Click event of a command button?

  3. #3
    2 Star Lounger
    Join Date
    May 2002
    Location
    Jerusalem, Israel
    Posts
    187
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: GoToControl (Access 2000)

    Hans,

    Thanks for your response. I neglected to mention that there are also other options on that screen to choose from. If the search code is associated with the After Update event of the combo box, then it won't give you a chance to select any additional options.

    However, the vast majority of searches only involve this combo box so that is why I wanted to be able to press the enter key and perform the search from the combo box. But there are times that users will want to also select other options to limit the search or search by other criteria.

    My ideal scenario would be to use the combo box, tab to other fields if necessary and then press "Enter" on the keyboard to begin the search.

    Thanks,

    JoeK

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

    Re: GoToControl (Access 2000)

    You could put code in the On Key Down event of the combo box and test whether the Enter key has been pressed. For a combo box named cboSearch:

    Private Sub cboSearch_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyReturn Then
    ' call your search code here
    End If
    End Sub

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

    Re: GoToControl (Access 2000)

    Alternatively, you can set the Key Preview property of the form to Yes and use the On Key Down event of the form:

    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyReturn Then
    ' code goes here
    End If
    End Sub

    This event will occur whenever the user presses a key anywhere in the form, so you'll have to check ActiveControl to know where the user pressed Enter.

  6. #6
    2 Star Lounger
    Join Date
    May 2002
    Location
    Jerusalem, Israel
    Posts
    187
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: GoToControl (Access 2000)

    Thanks for your reply.

    I am trying to implement the code you gave me, but I have not been successful. I have never called code from another subroutine before and don't really know how to do it. I took my best shot, though. Perhaps you can help.

    The code for the search is found here: Private Sub ButtonSearch_Click()

    I tried:

    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyReturn Then
    ButtonSearch
    End If
    End Sub

    and

    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyReturn Then
    Call ButtonSearch
    End If
    End Sub

    But neither worked. How do you actually call the code?

    Thanks for your help again.

    JoeK

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

    Re: GoToControl (Access 2000)

    As you note yourself, the search procedure is called ButtonSearch_Click, so you must use that name: either

    ButtonSearch_Click

    or

    Call ButtonSearch_Click

  8. #8
    2 Star Lounger
    Join Date
    May 2002
    Location
    Jerusalem, Israel
    Posts
    187
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: GoToControl (Access 2000)

    Thanks. I tried both Call ButtonSearch_Click and just ButtonSearch_Click but I get an Application Error.

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

    Re: GoToControl (Access 2000)

    Could you post a stripped down copy of your database? See <post#=401925>post 401925</post#> for instructions.

  10. #10
    2 Star Lounger
    Join Date
    May 2002
    Location
    Jerusalem, Israel
    Posts
    187
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: GoToControl (Access 2000)

    Hans,

    Thanks, but I'd prefer not to. Anyway, I think this might be a case of working for a long time to achieve a time saving of a few seconds.

    I'm going to give up on this one.

    Thanks for trying to help out.

    JoeK

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

    Re: GoToControl (Access 2000)

    Try this:

    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyReturn Then
    If Me.ActiveControl = Me.cboSearch Then
    Call ButtonSearch_Click
    KeyCode = 0
    End If
    End If
    End Sub

    Replace cboSearch with the name of the search combo box. If this works, you can expand the code to handle other controls too.

  12. #12
    2 Star Lounger
    Join Date
    May 2002
    Location
    Jerusalem, Israel
    Posts
    187
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: GoToControl (Access 2000)

    Hans,

    I got another application error. However, I found a second-best workaround that actually does the job but not as smoothly as I would have hoped.

    I converted a macro to VBA code and am calling it from within the code you gave me that identifies when the Enter button is pressed. This is being run from the combo box. The advantage of this over a straight macro is that if you press "Enter", the focus goes to the "Search" button (so you just press the "Enter" key again to activate the search); but if you press the "Tab" key, the focus goes to the next field, which is handy if you want to limit your search further.

    So in the end you did help me out quite a bit!

    Thanks,

    JoeK

Posting Permissions

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