Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2003
    Posts
    18

    Unanswered: Close Form IF combo box contains value

    I have a combo box on a form which has a blank default value.

    I want to force the user to choose either Yes or No from the combo box before he / she closes the form.

    Is there any way of putting a command on the close action of the form to check for a value in the combo box before closing, if no value then do nothing ??

    Thanks for your help

    Dave

  2. #2
    Join Date
    Apr 2002
    Location
    Germany
    Posts
    228
    Use the Unload event instead:

    Code:
    Private Sub Form_Unload(Cancel As Integer)
        If IsNull(Me.MyCombo) then
            Cancel = True 'prevents form close
        End If
    End Sub

  3. #3
    Join Date
    Oct 2003
    Posts
    18
    That's exactly what i needed thanks.

    Is there a way of popping up an error message as a reminder to fill it in if they haven't ?

  4. #4
    Join Date
    Apr 2002
    Location
    Germany
    Posts
    228
    Well sure, just add an appropriate MsgBox to the code with the message to the user.

  5. #5
    Join Date
    Jun 2003
    Posts
    19

    Code

    Here is a little code if you need it.

    Dim Response As Variant
    Response = MsgBox("YOUR MESSAGE", vbOKCancel, "Message Box Name")

    If Response = vbOK Then 'If OK selected do something

    End if

    Hope this helps

  6. #6
    Join Date
    Oct 2003
    Posts
    18
    thats brilliant guys, thanks for your help.

Posting Permissions

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