Results 1 to 7 of 7
  1. #1
    2 Star Lounger
    Join Date
    Mar 2005
    Location
    Anderson, Indiana, USA
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    SetFocus Problems

    I have a sub form, frm_2_prod_part_input, that if the part number field is left blank, I would like them to fill in that field before they enter in the rest of the information in the subform. The main form is called frm_1_prod_line_input. I have tried to set the focus to the main form then back to the sub form then back to the control plus a couple other things. What ever I have tried I can not get to work and now a loss of what the correct way is.

    Private Sub prod_part_nbr_LostFocus()
    If IsNull(Me.prod_part_nbr) Then
    MsgBox "The part number must filled in please.", vbInformation, "Missing Part Number"
    Me.prod_part_nbr.SetFocus
    End If
    End Sub

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

    Re: SetFocus Problems

    See the recent thread starting at <post#=473938>post 473938</post#>. You can use the On Exit event of the control, and set its Cancel argument to True if necessary:

    Private Sub prod_part_nbr_Exit(Cancel As Integer)
    If IsNull(Me.prod_part_nbr) Then
    MsgBox "The part number must filled in please.", vbInformation, "Missing Part Number"
    Cancel = True
    End If
    End Sub

    However, I would prefer not to do it this way, but to use the Before Update event of the form to check whether the part number has been filled in (cf. Mark Liquorman's remarks in the thread I referred to)

  3. #3
    2 Star Lounger
    Join Date
    Mar 2005
    Location
    Anderson, Indiana, USA
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SetFocus Problems

    This was a good solution, and I understand what Mark Liquorman was saying and already planned for it. This was just a sample of what I was using as I have before update event as well with the same problem. Why can I not get access to set the focus back to that field in the subform? I can do it in the main form just not the sub form to catch any left out fields and duplicating errors before they happen. If you have any other thoughts or if it is even possible, might just be limitation in Access.

    Thanks for the input

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

    Re: SetFocus Problems

    Are you still having a problem, or is it solved now?

  5. #5
    2 Star Lounger
    Join Date
    Mar 2005
    Location
    Anderson, Indiana, USA
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SetFocus Problems

    Hans,

    Using your solution that you provided like in the post 473938, I was able to solve that problem. I still do not understand why the setfocus does not set back to the control on the sub form.
    I have tried the solutions from the Microsoft knowledge base and I do not see where I am going wrong. I can get the focus to set on the main form and even the nested sub form on the sub form, just not in the subform itself.

    Thank You for the help on solving the initial problem as it works like a charm.

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

    Re: SetFocus Problems

    Trying to set the focus back to a control in an event of that control itself is tricky; that's why evenst such as Before Update and On Exit provide a Cancel argument. Setting focus to a control in another form (such as the parent form) is different, because that doesn't interfere with the focus on the form running the code.

  7. #7
    2 Star Lounger
    Join Date
    Mar 2005
    Location
    Anderson, Indiana, USA
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SetFocus Problems

    Hans,

    Once again you are a life saver; I was going nuts trying to figure out why I could not set the focus back. I thank you for the advice and your time.

Posting Permissions

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