Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Mandatory Field (A2K)

    I've gone through all of the postings and have tried the various examples, the majority of which suggest using the Form Before Update scenario.
    What I would like is based on the entering of data in a memo field.

    DataName: F01_Fault
    ControlName: txt_Fault

    I want to have the field flagged immediatley upon exiting/tabbing out
    I want a message identifying the missing data situation
    I do not want to use the Form Before Update scenario.

    As always, seemingly simple until I get my hands on it. And, thanks in advance for any help,
    Cheers,
    Andy

  2. #2
    4 Star Lounger
    Join Date
    Sep 2004
    Location
    Sacramento, California, USA
    Posts
    432
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Mandatory Field (A2K)

    You could use the field's OnExit Event
    Carla

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

    Re: Mandatory Field (A2K)

    Carla,

    Thanks kindly for responding. Here's what I tried:

    Got this from Charlotte's post 151359

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If IsNull([MarketID]) Then
    Cancel = True
    MsgBox "You must select a MarketID value in order to save this record."
    Me!MarketID.SetFocus
    End If
    End Sub

    1. I tried this using On Exit:

    Private Sub txt_Fault_Exit(Cancel As Integer)
    If IsNull([F01_Fault]) Then
    Cancel = True
    MsgBox "You must enter a Fault in order to save this record."
    txt_Fault.SetFocus
    End If
    End Sub

    This version does not let me out of the field, as it keeps coming up with the Fault message.

    2. I eliminated the Cancel = True line

    Private Sub txt_Fault_Exit(Cancel As Integer)
    If IsNull([F01_Fault]) Then
    'Cancel = True
    MsgBox "You must enter a Fault in order to save this record."
    Me!txt_Fault.SetFocus
    End If
    End Sub

    This version let's me out of the Fault field,
    - gives me the message,
    - Does Not SetFocus,
    - so I tab back and enter a Fault comment, and
    - get the message again when I come out,
    - but it allows me to continue and when I save the record, all data is in place.

    Not sure why I get the 2nd message, but it works, almost.

    Thanks for the advice. Any further comments or suggestions from anyone would be appreciated as always.
    Cheers,
    Andy

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

    Re: Mandatory Field (A2K)

    > This version does not let me out of the field, as it keeps coming up with the Fault message.

    But isn't that what you wanted - prevent the user from exiting the control is it hasn't been filled in? BTW, if you set Cancel to True, you don't need the SetFocus because the user is already in the txt_Fault control (this is different from the Before Update event of the form, because the user may be in a different control when that event occurs.)

    Private Sub txt_Fault_Exit(Cancel As Integer)
    If IsNull([F01_Fault]) Then
    Cancel = True
    MsgBox "You must enter a Fault in order to save this record."
    End If
    End Sub

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

    Re: Mandatory Field (A2K)

    Hans,

    Thanks for your reply. Entered your code exactly as you prescribed, and

    1. I enter a new record
    2. Tab into the fault field
    3. Do not enter anything
    4. Try to tab out of the fault field
    5. I get the "Message"
    6. The cursor is still in the fault field
    7. I enter a Fault description
    8. Attempt to tab out of the fault field,
    9. And, I get the message again
    10. Continuously

    This was grasping at straws, but because it is a Memo Field that's causing me this problem, I tested it on a text field and it worked perfectly.
    So, unless there is a work around for this, turning this Memo Field into a text field will not cause me much grief. If they can't spell out their problem in less than 255 characters, they should learn shorthand. Just kidding, a text field will suffice.

    Thanks again, Carla and Hans for your help. I suspect if I had tried the text vs. memo scenario before, it might have worked.
    Cheers,
    Andy

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

    Re: Mandatory Field (A2K)

    Try this:

    Private Sub txt_Fault_Exit(Cancel As Integer)
    If Trim(Nz(txt_Fault])) = "' Then
    Cancel = True
    MsgBox "You must enter a Fault in order to save this record."
    End If
    End Sub

    Note that the code now tests the control txt_Fault instead of F01_Fault.

  7. #7
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Mandatory Field (A2K)

    Save yourself alot of pain and suffering and just put your code in the form's BeforeUpdate event. Trying to put code in a control's BeforeUpdate (other than to check for wrong entries, rather than missing entries) or Exit event causes all sorts of problems, as you described in your later messages. Also, it doesn't catch the one big problem, what happens when the user doesn't tab to a field but rather uses the mouse to skip over that field and move directly to another one!
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

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

    Re: Mandatory Field (A2K)

    Hans,

    Not surprisingly, dead perfect! Thanks again,
    Cheers,
    Andy

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

    Re: Mandatory Field (A2K)

    Mark, thanks for jumping in with your usual sage advice. Under normal circustances what you suggest would be correct, but In this particular instance, this form is handled in a non-mousing, tabbing scenario in order to speed up data entry. This system is a complete rewrite from what was an old DOS-Based Q & A system and they are totally, anti-mouse where at all possible. Go figure. Anyway, appreciate your input which will obviously be applicable in any of my more normal future applications. If I ever get to see one,
    Cheers,
    Andy

  10. #10
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Mandatory Field (A2K)

    While you may expect the users will tab from field to field, can you be 100% sure they will do that every time? My experience is such that I expect them to do the unexpected, and I am seldom disappointed!
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

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

    Re: Mandatory Field (A2K)

    Mark,

    We all know the old "Thou Shalt Not Assume" adage. But, are you ready for this. In this particular case the person doing the receiving keeps the mouse in a drawer, because at this particular station where the Receiving is done, the only thing happening is this one form only. I had to make all actions KeyDown-types in order to negate the use of the mouse. However, we both know that someone is going to come along and burn me at some point. So, I'm going to create a duplicate of this form using your approach and hide it until such time as they have a problem. And then I can childishly say, "Mark told me you'd do this!" Immatureally yours,
    Cheers,
    Andy

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

    Re: Mandatory Field (A2K)

    Hans,

    Just to let you and anyone else looking in, this was the final version that worked perfectly:

    Private Sub txt_Fault_Exit(Cancel As Integer)
    Dim intButType As Integer
    Dim strMsgPrompt As String, strMsgTitle As String
    If Trim(Nz([txt_Fault])) = "" Then
    strMsgPrompt = "You must enter a Fault in order to " & vbCrLf & _
    "to continue entering data" & vbCrLf & _
    " for this Item"
    strMsgTitle = "No Fault Described!!"
    intButType = vbExclamation
    MsgBox strMsgPrompt, intButType, strMsgTitle
    Cancel = True
    End If
    End Sub


    That being said, nothing is ever so good that I can't mess with it to enhance it. I know from previous messages on the board, you should not mess with the appearance of messages in order to maintain Windows-like appearance. After all we do not want to insult Redmond.
    However, is it possible to change/enhance the font within a "message box" because sometimes bigger and bolder is better. Just curious. Not crucial,
    Cheers,
    Andy

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

    Re: Mandatory Field (A2K)

    No, the message box is "fixed". You could create your own custom form, howver, to serve as message box. Set its Modal property to True, so that the user has to close it in order to continue.

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

    Re: Mandatory Field (A2K)

    Hans,

    This variation on the previous theme

    Private Sub txt_Fault_Exit(Cancel As Integer)
    If Trim(Nz([txt_Fault])) = "" Then
    DoCmd.OpenForm "frm_XError_Fault"
    Else
    End If
    End Sub

    does allow me to bring up a modifiable form ( frm_XError_Fault ) so that I can change the fonts, etc. That's the good news. The bad news is that it is not as efficient or foolproof as your original suggested approach. This one, upon exiting the Message Form, went on to the next field and the operator would have to tab back, which is not cool. I did try variations on SetFocus, but go nowhere. Anyway, it was an interesting exercise.
    Cheers,
    Andy

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

    Re: Mandatory Field (A2K)

    That's because you left out the Cancel = True again. <img src=/S/crazy.gif border=0 alt=crazy width=15 height=15>

Page 1 of 2 12 LastLast

Posting Permissions

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