Results 1 to 13 of 13
  1. #1
    5 Star Lounger bfxtrfcmgr's Avatar
    Join Date
    Aug 2002
    Location
    Fresno, California, USA
    Posts
    995
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Code help (2002)

    I want to notify the user that an entry cannot be changed to "null". This doesn't seem to be working (Lost Focus event):
    <pre> If IsNull(Me.cboClass) Then
    MsgBox "Every participant MUST be assigned to a class!", vbInformation
    Me.cboClass.SetFocus
    End If</pre>

    Bryan,
    Not the smartest critter on the glacier. . .
    . . .but I'm persistent (does that count?)

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

    Re: Code help (2002)

    Use the Before Update event of the control and insert a line

    Cancel = True

    just above the End If.

  3. #3
    5 Star Lounger bfxtrfcmgr's Avatar
    Join Date
    Aug 2002
    Location
    Fresno, California, USA
    Posts
    995
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Re: Code help (2002)

    Hmm. . . .still nothing. Might there be other If IsNull code conflicting? There is some code in the After Update event.
    <pre> If IsNull(Me.cboClass) Then
    MsgBox "Every participant MUST be assigned to a class!", vbInformation
    Me.cboClass.SetFocus
    Cancel = True
    End If</pre>

    Bryan,
    Not the smartest critter on the glacier. . .
    . . .but I'm persistent (does that count?)

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

    Re: Code help (2002)

    Cancel = True has no effect in the After Update event, it MUST be in the Before Update event. However, this event only fires if the user changes something, it doesn't occur if the user just tabs into and out of the control.
    Is cboClass bound to a field? If so, you can also set a validation rule Is Not Null on the field in the underlying table.

  5. #5
    5 Star Lounger bfxtrfcmgr's Avatar
    Join Date
    Aug 2002
    Location
    Fresno, California, USA
    Posts
    995
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Re: Code help (2002)

    Sorry Hans, I must not be following here. I do have it in the Before Update event:
    <pre>Private Sub cboClass_BeforeUpdate(Cancel As Integer)
    On Error GoTo Err_BeforeUpdate

    Dim stDocName As String

    stDocName = "frmAllParticipants"

    If IsNull(Me.cboClass) Then
    MsgBox "Every participant MUST be assigned to a class!", vbInformation
    Me.cboClass.SetFocus
    Cancel = True
    End If

    Exit_BeforeUpdate:
    Exit Sub

    Err_BeforeUpdate:
    MsgBox Err.Description
    Resume Exit_BeforeUpdate

    End Sub</pre>

    I placed a validation rule and text in the table, but still no msg if you enter cboClass, delete the entry, and tab out of the control. I want the user to be able to edit (change) the selection, but not to leave it as null.
    Bryan,
    Not the smartest critter on the glacier. . .
    . . .but I'm persistent (does that count?)

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

    Re: Code help (2002)

    I don't understand what the variable stDocName is doing in there - it isn't used.

    It isn't necessary to include the line Me.cboClass.SetFocus, for setting Cancel = True will (or should) prevent the user from leaving the control.

    Apart from that, the code looks OK, it should prevent the user from clearing the combo box. If you wish, you can post a stripped down and zipped copy of the database.

  7. #7
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Code help (2002)

    Why don't you set a breakpoint on the command:
    If IsNull(Me.cboClass) Then
    and use the mouse to hover over Me.cboClass and see what the value is.

  8. #8
    5 Star Lounger bfxtrfcmgr's Avatar
    Join Date
    Aug 2002
    Location
    Fresno, California, USA
    Posts
    995
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Re: Code help (2002)

    Pat:

    When the value is null:
    Me.cboClass = ""

    I can't get this monster stripped down enough to attach, so I may just have to abandon the whole idea and leave as is. BTW, conditional formatting doesn't work on that control either; if I set a condition for null. Thanks for the input!
    Bryan,
    Not the smartest critter on the glacier. . .
    . . .but I'm persistent (does that count?)

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

    Re: Code help (2002)

    So the value is not null, but an empty string. Try this:
    <code>
    If Me.cboClass & "" = "" Then
    </code>
    instead of
    <code>
    If IsNull(Me.cboClass) Then</code>

  10. #10
    5 Star Lounger bfxtrfcmgr's Avatar
    Join Date
    Aug 2002
    Location
    Fresno, California, USA
    Posts
    995
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Re: Code help (2002)

    That was it Hans. Does this have to do with numbers v. text? The class "numbers" (i.e.2005.1) are not numbers at all, they're text (I just looked)! In any case, and for my info, if an entry is deleted, I suppose at this point, that does not necessarily mean that it is "null"?
    Bryan,
    Not the smartest critter on the glacier. . .
    . . .but I'm persistent (does that count?)

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

    Re: Code help (2002)

    If a text field has its Allow Zero Length property set to Yes, it can be "" if cleared. If Allow Zero Length is No, clearing the field results in Null.

  12. #12
    5 Star Lounger bfxtrfcmgr's Avatar
    Join Date
    Aug 2002
    Location
    Fresno, California, USA
    Posts
    995
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Re: Code help (2002)

    Hans:

    Thanks for the explanation! I presume then, if you're going to use text to diplay a number, it should be set to "no" for Allow Zero Length. I looked at tblMaster and found a bunch of class "numbers" that were significantly different (i.e. 2005.1, 2003.2.2, 2004.1.10), I guess that's why it's a text field? Thanks for the help. . . again!
    Bryan,
    Not the smartest critter on the glacier. . .
    . . .but I'm persistent (does that count?)

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

    Re: Code help (2002)

    I usually set Allow Zero Length to No for text fields. The only time this causes problems is if you try to import data from other applications into an existing table. Such data may contain empty strings.

Posting Permissions

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