Results 1 to 15 of 15
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Posts
    254
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Make the user select from combo box (Access 2000)

    How to make the user select from a combo box?


    In my form Clients I have a combo box called TypeID, and it is very important to me that the user does not forget to choose from the combo box.
    It is essential when populating a new client, that the user does not forget it and i think i might put something in the OnClose event of the form,to infrom the user that he must choose form the combo box. My idea is the following

    OnClose event:

    If IsNull(Me.TypeID) Then
    MsgBox "Please choose from the combo box"
    DoCmd.CancelEvent
    end if

    To my regret my code does has any effect. the form closes all right. Can somebody help me write a true event forbidding the customer to close
    the form when the combo box is not chosen?

  2. #2
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Make the user select from combo box (Access 2000)

    Have you tried the Unload Event:

    Private Sub Form_Unload(Cancel As Integer)
    If IsNull(Me.TypeID) Then
    MsgBox "Please choose from the combo box"
    DoCmd.CancelEvent
    Me.TypeID.SetFocus
    End If
    End Sub

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Make the user select from combo box (Access 2000)

    Or:

    <pre>Private Sub Form_Unload(Cancel As Integer)
    Dim intMsg As Long
    If IsNull(Me.TypeID) Then
    intMsg = MsgBox("Do You Really Want To Exit This Form" & vbCrLf & _
    "Without Selecting From The Combo", vbOKCancel, "Close Form")

    Select Case intMsg
    Case vbOK
    If Err = 2501 Then
    DoCmd.Close acForm, Me.Name
    End If
    Case vbCancel
    DoCmd.CancelEvent
    Me.TypeID.SetFocus
    Exit Sub
    End Select
    End If
    End Sub</pre>


    This will give the user to either close or not

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

    Re: Make the user select from combo box (Access 2000)

    Dave,

    The code you posted should work fine. I know that you used DoCmd.CancelEvent because that is in the original post. Just FYI, since the Unload event has a Cancel argument, it is cleaner to use that than DoCmd.CancelEvent, which is mainly meant for compatibility with macros.

    Private Sub Form_Unload(Cancel As Integer)
    If IsNull(Me.TypeID) Then
    MsgBox "Please choose from the combo box"
    Cancel = True
    Me.TypeID.SetFocus
    End If
    End Sub

  5. #5
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Make the user select from combo box (Access 2000)

    Thanks for your update and information Hans.
    I didn't know, but I've seen the (Cancel as Integer) many a time, so again, this makes better sense now.
    Have fun

    p.s

    This makes me a bronze lounger <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23>

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

    Re: Make the user select from combo box (Access 2000)

    <img src=/S/fanfare.gif border=0 alt=fanfare width=31 height=23> Congratulations!

    It must be in the air: three new Bronze Loungers in one week - <!profile=JohnGray>JohnGray<!/profile>, <!profile=Bowlie>Bowlie<!/profile> and you.

  7. #7
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Make the user select from combo box (Access 2000)

    Aaaaaahhhhh but there's a difference !

    They do most of the answering, and I do most of the asking <img src=/S/rofl.gif border=0 alt=rofl width=15 height=15> <img src=/S/rofl.gif border=0 alt=rofl width=15 height=15>

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

    Re: Make the user select from combo box (Access 2000)

    Well done Dave, I'm approaching the 2000 whatever that is.

  9. #9
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Make the user select from combo box (Access 2000)

    patt

    You're safe for another 500, but I think 10000 and over should be <font color=448800>Kryptonite Lounger</font color=448800>

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

    Re: Make the user select from combo box (Access 2000)

    Oh drat, I thought it may have been a Gold Lounger.
    BTW you have been contributing very well of late.

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

    Re: Make the user select from combo box (Access 2000)

    Yet, that was number 2000! Thanks for all the help you give. <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15>

  12. #12
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Make the user select from combo box (Access 2000)

    patt

    Thanks for the encouragement, I only learned it from here.

    <img src=/S/whisper.gif border=0 alt=whisper width=29 height=17>Shhhhhhhhh !! <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15>This thread is going off target, I feel a locked thread or ticking off coming <img src=/S/scold.gif border=0 alt=scold width=50 height=15> <img src=/S/cop.gif border=0 alt=cop width=15 height=24>

  13. #13
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Louisville, Kentucky, USA
    Posts
    605
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Make the user select from combo box (Access 2000)

    Just a thought, but wouldn't this work?

    In the OnExit of the control BEFORE the combo box, put:

    DoCmd.GoToControl "TypeID"

    and in OnExit of "TypeID" put

    If IsNull(Me.TypeID) Then
    MsgBox "You must make a selection from this list"
    Me.TypeID.SetFocus
    End If

    This way the user is directed to TYPEID and can't forget to fill it in.
    Roberta
    Roberta Price <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

  14. #14
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Make the user select from combo box (Access 2000)

    I suppose it would really but, only if it was entered in the first place.

    If there are many controls on the form and the user never enters the control in the first place, the code could never be fired.

  15. #15
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Louisville, Kentucky, USA
    Posts
    605
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Make the user select from combo box (Access 2000)

    Dave,

    I agree and stand corrected. I should have said a control that the developer knows the users WILL enter. Therefore, the first OnExit will take the user to TYPEID, the second won't let the user leave until it's filled in, and finally in the AfterUpdate, code that will take the user to the next appropriate control.

    Roberta
    Roberta Price <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

Posting Permissions

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