Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    jo15765's Avatar
    jo15765 is offline Expert
    Windows XP Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672

    Field Not Gaining Focus

    I have a check put in place for the Exit() event of a form field. The issue I have is that the user hits the tab key to move to the next field, and a warning is popped up. Then the field is cleared and should regain focus, but the tab is taking the cursor to the next field. What I want is for the cursor to go back to the [Schedule #] field, and am mind blown on this as I tried the fully qualified field name, as well as the ME!



    Code:
    Private Sub ScheduleNum__Exit(Cancel As Integer)
        MsgBox ("Are you sure you want to remove this value?")
        Forms![Scheduling Assistant].[Schedule #] = Null
        Forms![Scheduling Assistant].[Schedule #].SetFocus
        Me![Schedule #.SetFocus
    End Sub

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    It probably needs a close bracket "]" :
    Me![Schedule #].SetFocus

    It is not a good idea to put anything but letters or maybe an underscore "_" in an objects name. It can cause a variety of issues.
    I personally use CamelFontNames!

  3. #3
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    Quote Originally Posted by RuralGuy View Post
    It probably needs a close bracket "]" :
    Me![Schedule #].SetFocus

    It is not a good idea to put anything but letters or maybe an underscore "_" in an objects name. It can cause a variety of issues.
    I personally use CamelFontNames!
    Even adding the closing bracket it still tabs to the next field.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Does this all take place within the Scheduling Assistant Form?

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Are you using the MsgBox there?

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Is this Exit code for the Control to which you want to return?

  7. #7
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    Quote Originally Posted by RuralGuy View Post
    Is this Exit code for the Control to which you want to return?
    Yes this is exit code for the text box I want to return to.

    Yes I am using the msgbox there

    Yes all of this takes place in the Scheduling Assistant Form.

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Use the BeforeUpdate event on this control for this function. That event can be cancelled and leave you in the same control.

  9. #9
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    Quote Originally Posted by RuralGuy View Post
    Use the BeforeUpdate event on this control for this function. That event can be cancelled and leave you in the same control.
    I moved the syntax to my before update and same issue occurs. The cursor just moves on to the "Tab" field and does not revert back.

    Edit -->
    Stepping through the code, using BeforeUpdate actually will bring focus back to the original field, but once the user gains control of the form again they are in the next field.

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Your code needs to look something like:
    Code:
    Private Sub ScheduleNum_BeforeUpdate(Cancel As Integer)
    If (Me!ScheduleNum & "") = "" Then
       If MsgBox("Are you sure you want to remove this value?", vbCritical + vbYesNo + vbDefaultButton2) = vbYes Then
           Cancel = True
       End If
    End If
    End Sub
    BTW...this code calls the ControlName "ScheduleNum" and not [Schedule #].

  11. #11
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    Quote Originally Posted by RuralGuy View Post
    Your code needs to look something like:
    Code:
    Private Sub ScheduleNum_BeforeUpdate(Cancel As Integer)
    If (Me!ScheduleNum & "") = "" Then
       If MsgBox("Are you sure you want to remove this value?", vbCritical + vbYesNo + vbDefaultButton2) = vbYes Then
           Cancel = True
       End If
    End If
    End Sub
    BTW...this code calls the ControlName "ScheduleNum" and not [Schedule #].
    This leaves no field on my form with focus, and if I try to add focus

    I get an error of:
    Run-time error '2108':


    You must save the field before you execute the GoToControl action, the GoToControl method, or the SetFocus method

  12. #12
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    I think I am seeing what is going on, since the field [SChedule #] is a bound control - when I leave that control my form wants to save the entry into the database (even though the message box is telling the user that you can't).

    Essentially what I am after is a way that <strong>IF</strong> that message box is displayed then trash this record (don't save anything) and force the user to create a new record.

    AM I going about this the incorrect way?

  13. #13
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Did you comment out the Exit Event code? What I posted does not try and change records.

  14. #14
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Quote Originally Posted by jo15765 View Post
    This leaves no field on my form with focus, and if I try to add focus

    I get an error of:
    Run-time error '2108':


    You must save the field before you execute the GoToControl action, the GoToControl method, or the SetFocus method
    The focus is still in the same control!

  15. #15
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    Quote Originally Posted by RuralGuy View Post
    Did you comment out the Exit Event code? What I posted does not try and change records.
    Yes, I did a straight copy/paste of your code into mine with the exception of leaving the field name as two words (I can not change that).

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 0
    Last Post: 06-14-2016, 01:51 AM
  2. Replies: 17
    Last Post: 03-16-2014, 10:52 PM
  3. Easier approach to gaining a sumation
    By GraeagleBill in forum Programming
    Replies: 5
    Last Post: 08-22-2013, 10:15 AM
  4. HELP! Set Focus to Continuous Sub Form Field
    By asmith78 in forum Programming
    Replies: 1
    Last Post: 09-09-2011, 02:27 PM
  5. Set focus to a field on a subform
    By MiaAccess in forum Forms
    Replies: 11
    Last Post: 03-05-2011, 11:49 AM

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