Blank fields need to filled in

Ukraine82

Registered User.
Local time
Today, 14:44
Joined
Jun 14, 2004
Messages
346
I have pop up form for report selection. In my drop down i have certain reports that need to have start and end date.

I'm using this formula to show or hide start date field and end date field.

If Not [Report_Selection] = "VehiclesNotRecovered" Then
StartDate.Visible = True
EndDate.Visible = True

Else
StartDate.Visible = False
EndDate.Visible = False
End If

I would like to give the user a pop message to warn him/her fill in the start and end date field when selecting reports other than VehiclesNotRecovered.

If startdate and enddate fields not filled in and they run a report - they will get an #error message.

Thanks,
Michael
 
If I understand you question correctly, are you simply needing to validate the date entry boxes before proceeding to the report? If that's the case you can use something like this beneath your command button:

Code:
If Not IsDate(StartDate) Or Not IsDate(EndDate) Then
   MsgBox "You must enter a complete date range first.", vbExclamation
   Exit Sub
End If
 
Rich,

I was thinking about doing that, but I know in the future I will be asked to add more fields for a better search.

I ended up doing the module ValidateEntries

Public Function CheckForEntries() As Boolean
'On Error GoTo Err_CheckEntries

Dim strMessage As String
Dim ctl As Control
Dim strControl As String

'set all controls to normal white background
Call SetBackColorNormal

'if not a new record check each controls tag property for Req
If Not Screen.ActiveForm.NewRecord Then
For Each ctl In Screen.ActiveForm.Controls
If (ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox) And ctl.Tag = "Req" Then
'only build a message for the first required control without an entry
If Nz(Len(ctl.Value), 0) = 0 And Nz(Len(strMessage), 0) = 0 Then
'this function requires that the label for the control have the same name as the control
'followed by _Label
strMessage = Screen.ActiveForm(ctl.ControlName & "_Label").Caption & " is a required field."
'set the strControl variable to the name of the required control that is not filled in
strControl = ctl.ControlName
End If
End If
Next

'if there is no message, then all required controls have entries
If Nz(Len(strMessage), 0) > 0 Then
MsgBox strMessage, vbOKOnly, "Required field left blank!"
'set the back color of the required control in question to yellow
Screen.ActiveForm(strControl).BackColor = 65535 'Bright Yellow
'and set the focus to the control
Screen.ActiveForm(strControl).SetFocus
'and set the checkforentries to True so that any code in the form can be handled
CheckForEntries = True
Else
'if all required controls have entries set checkforentries to false
CheckForEntries = False
End If
End If

Exit_CheckEntries:
Exit Function

Err_CheckEntries:
MsgBox Err.Description
GoTo Exit_CheckEntries

End Function
_____________________________________
Public Sub SetBackColorNormal()
On Error Resume Next
Dim ctl As Control

For Each ctl In Screen.ActiveForm.Controls
If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
ctl.BackColor = -2147483643 'normal white back color
End If
Next

End Sub

There are more codes to it. They way I have it is any time you select a report it will ask a user to fill in certain fields to get certain information. The module above will give a user a pop up message along with highlighted text box.

hth,
Michael
 

Users who are viewing this thread

Back
Top Bottom