Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    513

    simple 'set focus' format question


    I would think that the below code would return the focus to the control, but it does not..? - what obvious thing have I got wrong?
    Code:
     Private Sub txtType_LostFocus()    If Len(Nz(Me.txtType, "")) < 1 Then        strText = "You must enter a fixture type before moving on..." & vbCrLf & _                  "Please try again"        strTitle = "FIXTURE TYPE MISSING"        Response = MsgBox(strText, vbCritical + vbRetryCancel, strTitle)'        Cancel = True        Me.txtType.SetFocus    End IfEnd Sub
    with many thanks in advance, Mark

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Difficult to read, but I think you want the before update event, not lost focus. I normally use the form's rather than each control:

    http://www.baldyweb.com/BeforeUpdate.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    As Paul said, validating code that ensures that a Control is populated, before saving the Record, simply has to be in the Form_BeforeUpdate event! Trying to validate this in an event tied to the Control, itself, is doomed to failure! All the user has to do, to circumvent your validation attempt, would be to simply never go into that Control...then none of its events would fire!

    Also, in order to use

    Cancel = True

    the event in question has to have a Cancel event, which

    Private Sub txtType_LostFocus()

    whereas, the Form's BeforeUpdate event does

    Private Sub Form_BeforeUpdate(Cancel As Integer)

    If your need here is to never let the user leave the Record without completing it, as your current code shows, this should do the trick:
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
     
     If Len(Nz(Me.txtType, "")) < 1 Then
     
      strText = "You must enter a fixture type before moving on..." & vbCrLf & "Please try again"
      
      strTitle = "FIXTURE TYPE MISSING"
    
      Response = MsgBox(strText, vbCritical + vbOKOnly, strTitle)
       
      Cancel = True
    
      Me.txtType.SetFocus
      
     End If
     
    End Sub

    Linq ;0)>

  4. #4
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    513
    I need to be more authoritairian that that:
    Whenever the form opens (or moves to a new current record) (or creates a new record) (<etc.>) AND that particular field is null or has a zero lenght string, (in reality, it ought to be possible on a new record, none the less...), the very first focus is to that feild, and the user ought to not be able to navigate anywhere else until that field has been entered and validated.


    So having said all this, your comments were a big help, and I (think) that I've been able to check this one off of my ToDo List!

    Thanks

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Glad you got it sorted.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by markjkubicki View Post

    ...the very first focus is to that feild, and the user ought to not be able to navigate anywhere else until that field has been entered and validated...
    You're not thinking this through. I can think of no better way to completely tick off your end users! There are going to be times, for whatever reason, when a user is going to need to leave a Record unfinished! Not saving an incomplete Record is perfectly acceptable...but making a user that needs to exit the Form hit <Ctrl> + <Alt> + <Del> in order to do so is not.

    Linq ;0)>

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

Similar Threads

  1. If and Else - very simple question
    By tygereye in forum Access
    Replies: 38
    Last Post: 04-02-2014, 06:06 AM
  2. Simple Date Format Question
    By EHittner in forum Queries
    Replies: 1
    Last Post: 03-10-2013, 04:46 PM
  3. Simple Format Question
    By evanesce in forum Access
    Replies: 2
    Last Post: 01-19-2012, 08:23 AM
  4. Simple question?
    By roads.zx in forum Access
    Replies: 0
    Last Post: 10-15-2009, 04:56 PM
  5. Very simple question!
    By fiddley in forum Programming
    Replies: 2
    Last Post: 04-28-2009, 02:16 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