Wrox Programmer Forums
|
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
 
Old November 16th, 2003, 08:25 PM
Authorized User
 
Join Date: Nov 2003
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to bjackman Send a message via MSN to bjackman
Default 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

 
Old November 17th, 2003, 11:40 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Change this

frmEmployeeNameIDSubform.Selected.Text

to this

Me.frmEmployeeNameIDSubform.Form.Selected.Text


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old November 17th, 2003, 11:47 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

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
 
Old November 19th, 2003, 02:26 AM
Authorized User
 
Join Date: Nov 2003
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to bjackman Send a message via MSN to bjackman
Default

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









Similar Threads
Thread Thread Starter Forum Replies Last Post
if/else statement mussa Beginning PHP 5 July 3rd, 2006 06:06 PM
What does the @ do in the following statement? kenn_rosie VB.NET 2002/2003 Basics 1 March 15th, 2006 12:20 PM
Like Statement Nitin_sharma Oracle ASP 2 May 10th, 2005 12:18 AM
Like Statement Nitin_sharma Oracle 4 February 12th, 2005 01:46 PM
Like statement Nitin_sharma Classic ASP Databases 7 February 1st, 2005 11:12 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.