Message Box If Combo Empty

frankbutcher

Registered User.
Local time
Today, 06:00
Joined
Aug 6, 2004
Messages
192
Hi All.
Hope someone can help.

I have a form with 2 combos (cboStart and cboEnd) and button to preview a report.

The report is made from a Query, with the following in the completion date:-

Between [Forms]![frmReporting]![cboStart] And [Forms]![frmReporting]![cboEnd]

The user then chooses the start date and end dates in the combo's.
What I would like to do is have a message box appear if the use forgets to enter either date.

Many Thanks for reading this.
Frank.
 
A quick easy way to do it is to go into the table view and make that specific field required. Only thing is, it doesn't give an error until it tries to save, and then it only says "A required value was not entered" or something along those lines. To get around that, put *s next to the values that are required, then put a footnote (required fields).

There's probably another way, but this is probably the easiest.
 
Hi.
Many thanks for your reply.
The trouble is, the combos are unbound, so do not appear on a table anywhere, so cannot make them required.....unless there is another way?

I tried taking a bit of code from another post and tried it for one combo, and sort of got it to work:---


---------------------------------------
Private Sub Command73_Click()
On Error GoTo Err_Command73_Click

If IsNull(cboStart) Then

MsgBox "You must enter a Start Date", vbCritical, "Data Required"

Else

End If


Dim stDocName As String

stDocName = "RptReporting"
DoCmd.OpenReport stDocName, acPreview

Exit_Command73_Click:
Exit Sub

Err_Command73_Click:
MsgBox Err.Description
Resume Exit_Command73_Click


End Sub

-----------------------------------

It will show the message box when the start date combois empty which is good, but will also show the report as well.

Any ideas

Thanks

Frank.
 
Private Sub Preview_Click()
' Preview report.
Dim strDocName As String

On Error GoTo Err_Preview_Click

'Check to see that ending date is later than beginning date.
If IsDate(BeginningDate) And IsDate(EndingDate) Then
If EndingDate < BeginningDate Then
MsgBox "The ending date must be later than the beginning date."
SetDate.Caption = "Set Ending Date"
SelectDate.SetFocus
Exit Sub
End If
Else
MsgBox "Please use a valid date for the beginning date and the ending date values."
Exit Sub
End If

strDocName = "YourReport"
DoCmd.OpenReport strDocName, acViewPreview


Exit_Preview_Click:
Exit Sub

Err_Preview_Click:
If Err = ConErrRptCanceled Then
Resume Exit_Preview_Click
Else
MsgBox Err.Description
Resume Exit_Preview_Click
End If

End Sub
 

Users who are viewing this thread

Back
Top Bottom