Results 1 to 8 of 8

Thread: Form Focus

  1. #1
    Join Date
    Nov 2005
    Posts
    79

    Unanswered: Form Focus

    I have the below listed code to ensure that a field is selected. However, everytime that I open the form, I get the message box "You cannot leave TYPE blank" How do I make the command come up once the field is selected?

    Private Sub CboType_LostFocus()
    'Requires a value for the type of of computer (Notebook or PC)
    If IsNull(Me.CboType) = True Then
    MsgBox ("You cannot leave TYPE blank")
    Me.CboType.SetFocus
    End If
    End Sub

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Does it happen RIGHT when the form opens, or is the control first in the tabl order and you can't get out of it? is there any code in your form's onopen/onload/oncurrent events?
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Nov 2005
    Posts
    79

    Start up

    It happens right when the form opens. The tab order for this item is 7.

  4. #4
    Join Date
    Dec 2003
    Location
    Dallas, TX
    Posts
    1,004

    Question

    Quote Originally Posted by miracleblake
    I have the below listed code to ensure that a field is selected. However, everytime that I open the form, I get the message box "You cannot leave TYPE blank" How do I make the command come up once the field is selected?

    Private Sub CboType_LostFocus()
    'Requires a value for the type of of computer (Notebook or PC)
    If IsNull(Me.CboType) = True Then
    MsgBox ("You cannot leave TYPE blank")
    Me.CboType.SetFocus
    End If
    End Sub
    Hi,

    Just checking on something to help me to understand. Wanting to know if you need to put the =True part at the end of the line? Can't if be just
    If IsNull(Me.CboType) Then ??? Again, just to help me to understand as I am by no means a guru here.

    thanks,
    BUD

  5. #5
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    Bud

    the two statements are equivalent.
    the isnull() function returns True or False
    ...so if blah is a null
    isnull(blah) evaluates to True
    isnull(blah) = True evaluates to True = True which itself evaluates to True

    so it becomes a personal style choice... i prefer
    if isnull(blah) then
    and
    if not isnull(blah)


    izy
    currently using SS 2008R2

  6. #6
    Join Date
    Nov 2005
    Posts
    79

    Not Working

    I still have the same problem, even when I remove the true statement (isnull and not isnull.)

  7. #7
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    You never answered whether you have other code in your forms onload/onopen events.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  8. #8
    Join Date
    Dec 2003
    Location
    Dallas, TX
    Posts
    1,004
    Hiya Izy,

    Thanks, as that is my style also and had been the only way I had seen it done. have a good day

    BUD

Posting Permissions

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