|
Subject:
|
If Statement Help
|
|
Posted By:
|
bjackman
|
Post Date:
|
11/16/2003 7:25:58 PM
|
I'm having a bear of a time with a If Then statement. I have a form that is used to input parameters for a report. It consists of a main form and 2 subforms. I'm trying to get a cmd button to check that all the parameters are present that the report needs. Here s the code i have so far:
Private Sub IndividualTrainingRpt_Click() On Error GoTo Err_IndividualTrainingRpt_Click
Dim stdocname As String stdocname = "Individual Training Report" If IsDate(Me.startdatetext.Value) = False Then MsgBox "Your start date is blank, this report requires a start date.", vbOKOnly + vbCritical Exit Sub End If If IsDate(Me.enddatetext.Value) = False Then MsgBox "Your end date is blank, this report requires an end date.", vbOKOnly + vbCritical Exit Sub End If If IsNumeric(frmEmployeeNameIDSubform.Selected.Text) = 0 Then MsgBox "You must select employee's for this report.", vbOKOnly + vbCritical Exit Sub End If DoCmd.OpenReport stdocname, acViewPreview Exit_IndividualTrainingRpt_Click: Exit Sub
Err_IndividualTrainingRpt_Click: MsgBox Err.Description Resume Exit_IndividualTrainingRpt_Click End Sub
The subform is frmEmployeeNameIDSubform, it has a selected filed that is text (yes/no) I need the if statement to check if this field is yes or no, if no, do the msgbox. Any help or if any more info is needed. Get back to me, i'll be watching this thread closely as this has me completely pissed off because i can't get it to work.
Thanks
|
|
Reply By:
|
SerranoG
|
Reply Date:
|
11/17/2003 10:40:59 AM
|
Change this
frmEmployeeNameIDSubform.Selected.Text
to this
Me.frmEmployeeNameIDSubform.Form.Selected.Text
Greg Serrano Michigan Dept. of Environmental Quality, Air Quality Division
|
|
Reply By:
|
SerranoG
|
Reply Date:
|
11/17/2003 10:47:20 AM
|
To elaborate on my previous reply, in general when you have a form with a subform, here's how you reference the controls (e.g. textbox, button):
Control 1 is on the form and Control 2 is on the subform.
A procedure called from the main form:
Me.Control1 Me.MySubForm.Form.Control2
A procedure called from the subform:
Me.Parent.Form.Control1 Me.Control2
Greg Serrano Michigan Dept. of Environmental Quality, Air Quality Division
|
|
Reply By:
|
bjackman
|
Reply Date:
|
11/19/2003 1:26:01 AM
|
Greg,
Thn for your great help. I finally got it to work. What this code is, when a user tries to print a report, it checks to make sure they have supplied all the parameters it needs. Here is the code. Thnx again
If IsDate(Me.startdatetext.Value) = False Then MsgBox "Your start date is blank, this report requires a start date.", vbOKOnly + vbCritical Exit Sub End If If IsDate(Me.enddatetext.Value) = False Then MsgBox "Your end date is blank, this report requires an end date.", vbOKOnly + vbCritical Exit Sub End If If (subTrainingEmployeeName.Form.Selected) = No Then MsgBox "You must select at least one employee for this report.", vbOKOnly + vbCritical Exit Sub End If If (subTrainingTopic.Form.Selected) = No Then MsgBox "You must select at least one training topic for this report.", vbOKOnly + vbCritical Exit Sub End If
|