Results 1 to 10 of 10
  1. #1
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exiting from Header (A2K)

    Based on code I found elsewhere in the Forum, I thought this would work when exiting from a ComboBox in the header to a specific field in the detail section, but it doesn't.

    Private Sub txt_UserId_Exit(Cancel As Integer)
    Me.Section(acDetail).Controls(0).SetFocus
    End Sub

    Also not sure why you can't refer to the specific field by name, i.e. txtRangeStart_01

    It freezes and goes nowhere.

    Open to any suggestions and thanks in advance for whatever they may be,
    Cheers,
    Andy

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

    Re: Exiting from Header (A2K)

    Controls(0) is the first control you placed in the detail section, not necessarily the first control in the tab order. If this control is a label, for example, it cannot receive the focus (you can click on a label, but you cannot make it the active control). And if it is a text box or similar, you cannot set focus to it if its Enabled property is set to No.
    It should be possible to refer to a control by its name.

  3. #3
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Exiting from Header (A2K)

    Good Morning, Hans!

    As always, I never seem to give you enough information. Here's how this works:

    I want the user to print labels based on criteria on a popup form.
    And this is done by the user pressing Function Key F6 on his original form

    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyF6 Then
    DoCmd.OpenForm "frm 01 CN - 01 - Login - Labels"
    End If
    End Sub

    And this works very nicely.

    The new popup form opens like this:

    Private Sub Form_Open(Cancel As Integer)
    Me.Move Left:=6048, Top:=3456
    Me.txt_UserId.SetFocus
    Me.txt_UserId = Null
    End Sub

    It opens up the form, places the form in a specific spot, moves the cursor to txt_UserId and clears out any previous data.

    And this works very nicely.

    The user selects his code id number and presses enter:

    And this DOES NOT WORK very nicely.
    And the whole thing stops/freezes right there.

    I've actually, for test purposes, cut the form down to the txt_UserId field in the header and txtRangeStart_01 field in the detail section in order to eliminate any unobvious anomolies during testing.

    I've set up two different versions of the code to test if I can ever get past the first box.

    Private Sub txt_UserId_Exit(Cancel As Integer)
    Me.Section(acDetail).Controls(1).SetFocus
    End Sub

    and

    Private Sub txt_UserId_Exit(Cancel As Integer)
    Me.Section(acDetail).txtRangeStart_01.SetFocus
    End Sub

    I hope this makes this scenario a little less muddy.
    Cheers,
    Andy

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

    Re: Exiting from Header (A2K)

    What happens if you use

    Private Sub txt_UserId_Exit(Cancel As Integer)
    Me.txtRangeStart_01.SetFocus
    End Sub

    You shouldn't refer to the section when referring to a control by its name.

  5. #5
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Exiting from Header (A2K)

    Hans,

    The code you suggested is in the format that I normally use and have never had a problem with.

    In this instance, the cursor remains in the text box and goes nowhere when I press enter, therefore it doesn't even get to test the code.

    It, like, Hangs Up. Very frustrating, particularly when I eventually find out it's something simple I'm missing,
    Cheers,
    Andy

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

    Re: Exiting from Header (A2K)

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

  7. #7
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Exiting from Header (A2K)

    Hans,

    It'll be my pleasure, but will take me a bit of time to trash the unwanted.
    Cheers,
    Andy

  8. #8
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Exiting from Header (A2K)

    Hans,

    I've attached the little troublemaker. Thanks in advance for your efforts on this.
    If the error is really stupid, maybe you could send me a private email.

    Anyway, when you open frm 01 CN - 01 - Login - Labels the cursor will be sitting in txt_UserId. Enter 99 or 66 and press enter and you'll see what my problem is.
    Attached Files Attached Files
    Cheers,
    Andy

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

    Re: Exiting from Header (A2K)

    The cause of the problem is that the form header section contains only one control that can have the focus: txt_UserId. The text box txt_UserName has its Enabled property set to No.
    As a consequence, pressing Enter or Tab doesn't make you exit txt_UserId, and hence the On Exit event doesn't occur.

    To get around this, you can do the following:
    - Place a command button in the form header.
    - Set the Transparent property of the command button to Yes.

    When you press Enter or Tab, the focus will start to move away from txt_UserId to the command button, and at that moment the On Exit event procedure will come into play and set focus to txtRangeStart_01.

  10. #10
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Exiting from Header (A2K)

    Hans,

    HAPPY NEW YEARS!!

    Thanks again for this solution and all of the others you've provided over the past year. I would be in a serious state were it not for all of your help,
    Cheers,
    Andy

Posting Permissions

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