Results 1 to 5 of 5
  1. #1
    shylock is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Sep 2018
    Location
    Dayton, Ohio
    Posts
    100

    If control IsNull need to SetFocus back to the Null control

    I have a continuous form with a Begin Date text box, among other text boxes. If the Begin Date is Null or contains no information when the user tabs off the Begin Date control I want to re-focus to the Begin Date box and force a date entry from the date picker. below is the validation code I am trying to use:

    Private Sub txtBeginDate_BeforeUpdate(Cancel As Integer)
    If IsNull(Me.txtBeginDate) Then


    myMsg = MsgBox("You must enter a Begin Date!", vbInformation, "Invalid Begin Date")
    Me.txtBeginDate.SetFocus
    Cancel = True
    End If
    End Sub

    I have also tried the same code for the On Lost Focus property.

    The problem is that the focus does not return to the Begin Date control. Can someone tell me what I am doing wrong?

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,398
    a better place to put your code is the form before update event - that way if the user does not go into the textbox, the code will still be triggered

  3. #3
    shylock is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Sep 2018
    Location
    Dayton, Ohio
    Posts
    100
    Ajax;

    Thanks for your answer. It works, but I really want to refocus to Begin Date as soon as the user tabs off the control. Do you have any other suggestions?

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,398
    if the control was null when the user tabs in and is still null when the user tabs out, there is no update. You could try using the control lost focus or exit events instead. But if the user never tabs in in the first place, the code will never run

  5. #5
    shylock is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Sep 2018
    Location
    Dayton, Ohio
    Posts
    100
    Ajax:

    Excellent point! I will revisit my code for the other control and write new code in form update event. Perhaps loop and case statement to apply to each separate control. Thank you.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 03-22-2017, 07:25 AM
  2. Replies: 4
    Last Post: 02-18-2016, 12:06 PM
  3. SetFocus on last added form control in subform
    By faythe1215 in forum Forms
    Replies: 12
    Last Post: 03-02-2015, 04:09 PM
  4. Control Source is Null
    By CementCarver in forum Forms
    Replies: 8
    Last Post: 06-07-2013, 10:40 AM
  5. SetFocus on Image Control??
    By tylerg11 in forum Forms
    Replies: 1
    Last Post: 07-21-2012, 03:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums