Question Message Boxes

iceburg

Registered User.
Local time
Today, 18:13
Joined
Feb 12, 2009
Messages
10
Hello,
I am trying to write a message box that appears when clicking a command button to close a form in order to check that the user has selected a option from a combo box.
I have used the MsgBox("Message") code before, however the form still closes after reading the message and clicking OK. Is there anyway to go back to the form after clicking OK, or only displaying the message box if the user has failed to select a value from the combo box?

Any help would be greatly appreciated as I am relatively new to Access.

Thanks,

Jim
 
Code:
If Msgbox("Close Form Now?",VbQuestion+vbYesNo,"What Next") = vbYes Then
   DoComd.Close
End If
 
If user is required to select a value from the combo box prior to processing the next function, you will need to build an error handling routine to do that. This is a logical step.

Code:
Private Sub cmdOK_Click()

   If HasRequiredData=True then
       'do what you want to do here.
   End If

End Sub

Private Function HasRequiredData() as Boolean

   Dim bHasData as Boolean

   bHasData = True

   If cboValue & "" = "" then
       bHasData = False
   End If

    If bHasData = Flase Then
        msgbox "Please select a value from the drop-down box"
    End If

    HasRequiredData = bHasData

End Function
 
or you can make your form 'flow' - i.e., have most controls disabled, except one. when that one is filled with data, have the 'next' control enable, and so on for each control.

when you get to the last required field for filling in, then make it enable a "next" or "ok" button at the bottom of the form... kind of like 'rewarding' the user for entering each bit of data.

edit: re-reading your first post. you could make this combo box enable the "ok" "save" "complete" "whatever" button on your form.
 

Users who are viewing this thread

Back
Top Bottom