 |
| Access VBA Discuss using VBA for Access programming. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

November 16th, 2003, 08:25 PM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
If Statement Help
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
|
|

November 17th, 2003, 11:40 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
|
|
Change this
frmEmployeeNameIDSubform.Selected.Text
to this
Me.frmEmployeeNameIDSubform.Form.Selected.Text
Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
|
|

November 17th, 2003, 11:47 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
|
|
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
|
|

November 19th, 2003, 02:26 AM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|
 |