PC Review


Reply
Thread Tools Rate Thread

Date parameters for report

 
 
gorsoft@hotmail.com
Guest
Posts: n/a
 
      29th Oct 2010
I am using a form opened in dialog mode to enter start and end dates
as parameters for a report. The form is opened when I call the report.
Once the date parameters are entered, I make the diaolog form
invisible and allow the rest of the report code to run.

The form is specified in a constant:Private Const ScheduleCriteriaForm
As String = "frmChooseReportDate2"
Then in the open event of the report:
DoCmd.OpenForm ScheduleCriteriaForm, acNormal, , , , acDialog
' See if criteria form is still open:
On Error Resume Next
Set objFRM = Forms(ScheduleCriteriaForm)
' Stop report from opening if criteria form is closed:
If Err.Number <> 0 Then
Cancel = True
End If

Then I build the code for the data source of the report (strSQL) and
the criteria (strWhere) and the rest of the report code is as follows:

'Initialize SELECT statement.
MyRecordsource = strSql
' Set RecordSource property of Details Report.
Reports!rptInvoiceSchedule.RecordSource = MyRecordsource


In the close event of the report, the invisible dialog box itself is
closed.

This all works fine but I want to insert error trapping code where the
user forgets to enter either or both of the date parameters (txtFrom
and txtTo) in the dialog box.

I have tried the following:

Select Case Forms!frmChooseReportDate2!txtFrom
Case Is = Null
strMsg = "You must enter a date in both fields."
If MsgBox(strMsg, vbOKCancel) = vbCancel Then Exit Sub
Case Is = Not Null
Select Case Me!txtTo
Case Is = Null
strMsg = "You must enter a date in both fields."
If MsgBox(strMsg, vbOKCancel) = vbCancel Then Exit Sub
Case Is = Not Null
'Do nothing
End Select
End select

But where should I place this code? I tried putting it in the View
Report button on the dialog form but this just hangs.

Any ideas appreciated.

Gina
 
Reply With Quote
 
 
 
 
gorsoft@hotmail.com
Guest
Posts: n/a
 
      30th Oct 2010
On Oct 29, 6:16*pm, "Arvin Meyer" <arv...@invalid.org> wrote:
> In the event of the form where you hide it, check for the missing values:
>
> If Len([txtStartDate & vbNullString) > 0 Then ' This one is OK
> * * If Len([txtEndDate & vbNullString) >0 Then
> ' Hide the form
> Else
> * * MsgBox "No way Jose, fill in the dates", vbOKOnly
> * * Exit Sub
> End If
> --
> Arvin Meyer, MCP, MVPhttp://www.datastrat.comhttp://www.accessmvp.comhttp://www.mvps.org/access
> Co-author: "Access Solutions", published by Wiley
>
> <gors...@hotmail.com> wrote in message
>
> news:ea20e6d0-33db-4f64-98c4-(E-Mail Removed)...
>
>
>
> >I am using a *form opened in dialog mode to enter start and end dates
> > as parameters for a report. The form is opened when I call the report.
> > Once the date parameters are entered, I make the diaolog form
> > invisible and allow the rest of the report code to run.

>
> > The form is specified in a constant:Private Const ScheduleCriteriaForm
> > As String = "frmChooseReportDate2"
> > Then in the open event of the report:
> > DoCmd.OpenForm ScheduleCriteriaForm, acNormal, , , , acDialog
> > ' See if criteria form is still open:
> > On Error Resume Next
> > Set objFRM = Forms(ScheduleCriteriaForm)
> > ' Stop report from opening if criteria form is closed:
> > If Err.Number <> 0 Then
> > Cancel = True
> > End If

>
> > Then I build the code for the data source of the report (strSQL) and
> > the criteria (strWhere) and the rest of the report code is as follows:

>
> > 'Initialize SELECT statement.
> > MyRecordsource = strSql
> > ' Set RecordSource property of Details Report.
> > Reports!rptInvoiceSchedule.RecordSource = MyRecordsource

>
> > In the close event of the report, the invisible dialog box itself is
> > closed.

>
> > This all works fine but I want to insert error trapping code where the
> > user forgets to enter either or both of the date parameters (txtFrom
> > and txtTo) in the dialog box.

>
> > I have tried the following:

>
> > Select Case Forms!frmChooseReportDate2!txtFrom
> > Case Is = Null
> > strMsg = "You must enter a date in both fields."
> > If MsgBox(strMsg, vbOKCancel) = vbCancel Then Exit Sub
> > Case Is = Not Null
> > * *Select Case Me!txtTo
> > * *Case Is = Null
> > * *strMsg = "You must enter a date in both fields."
> > * *If MsgBox(strMsg, vbOKCancel) = vbCancel Then Exit Sub
> > * *Case Is = Not Null
> > * *'Do nothing
> > * *End Select
> > End select

>
> > But where should I place this code? I tried putting it in the View
> > Report button on the dialog form but this just hangs.

>
> > Any ideas appreciated.

>
> > Gina- Hide quoted text -

>
> - Show quoted text -


Thanks for your reply Arvin but putting that code in the event of the
form where I hide it (the view report button) does nothing - no error
message - nothing. When I then close that dialog box, I can see an
error message about cancelling an event (OpenReportCancel or
something). There must be something in the open event of the report
(see code above) which is causing this.

Gina
 
Reply With Quote
 
gorsoft@hotmail.com
Guest
Posts: n/a
 
      3rd Nov 2010
On 30 Oct, 11:59, "gors...@hotmail.com" <gors...@hotmail.com> wrote:
> On Oct 29, 6:16*pm, "Arvin Meyer" <arv...@invalid.org> wrote:
>
>
>
>
>
> > In the event of the form where you hide it, check for the missing values:

>
> > If Len([txtStartDate & vbNullString) > 0 Then ' This one is OK
> > * * If Len([txtEndDate & vbNullString) >0 Then
> > ' Hide the form
> > Else
> > * * MsgBox "No way Jose, fill in the dates", vbOKOnly
> > * * Exit Sub
> > End If
> > --
> > Arvin Meyer, MCP, MVPhttp://www.datastrat.comhttp://www.accessmvp.comhttp://www.mvps.org/a...
> > Co-author: "Access Solutions", published by Wiley

>
> > <gors...@hotmail.com> wrote in message

>
> >news:ea20e6d0-33db-4f64-98c4-(E-Mail Removed)...

>
> > >I am using a *form opened in dialog mode to enter start and end dates
> > > as parameters for a report. The form is opened when I call the report..
> > > Once the date parameters are entered, I make the diaolog form
> > > invisible and allow the rest of the report code to run.

>
> > > The form is specified in a constant:Private Const ScheduleCriteriaForm
> > > As String = "frmChooseReportDate2"
> > > Then in the open event of the report:
> > > DoCmd.OpenForm ScheduleCriteriaForm, acNormal, , , , acDialog
> > > ' See if criteria form is still open:
> > > On Error Resume Next
> > > Set objFRM = Forms(ScheduleCriteriaForm)
> > > ' Stop report from opening if criteria form is closed:
> > > If Err.Number <> 0 Then
> > > Cancel = True
> > > End If

>
> > > Then I build the code for the data source of the report (strSQL) and
> > > the criteria (strWhere) and the rest of the report code is as follows:

>
> > > 'Initialize SELECT statement.
> > > MyRecordsource = strSql
> > > ' Set RecordSource property of Details Report.
> > > Reports!rptInvoiceSchedule.RecordSource = MyRecordsource

>
> > > In the close event of the report, the invisible dialog box itself is
> > > closed.

>
> > > This all works fine but I want to insert error trapping code where the
> > > user forgets to enter either or both of the date parameters (txtFrom
> > > and txtTo) in the dialog box.

>
> > > I have tried the following:

>
> > > Select Case Forms!frmChooseReportDate2!txtFrom
> > > Case Is = Null
> > > strMsg = "You must enter a date in both fields."
> > > If MsgBox(strMsg, vbOKCancel) = vbCancel Then Exit Sub
> > > Case Is = Not Null
> > > * *Select Case Me!txtTo
> > > * *Case Is = Null
> > > * *strMsg = "You must enter a date in both fields."
> > > * *If MsgBox(strMsg, vbOKCancel) = vbCancel Then Exit Sub
> > > * *Case Is = Not Null
> > > * *'Do nothing
> > > * *End Select
> > > End select

>
> > > But where should I place this code? I tried putting it in the View
> > > Report button on the dialog form but this just hangs.

>
> > > Any ideas appreciated.

>
> > > Gina- Hide quoted text -

>
> > - Show quoted text -

>
> Thanks for your reply Arvin but putting that code in the event of the
> form where I hide it (the view report button) does nothing - no error
> message - nothing. When I then close that dialog box, I can see an
> error message about cancelling an event (OpenReportCancel or
> something). *There must be something in the open event of the report
> (see code above) which is causing this.
>
> Gina- Hide quoted text -
>
> - Show quoted text -


Update:

As is usually the case with these things, if you look at the problem
long enough, you manage to sort it out yourself. A misplaced "End if"
was all that was wrong!

Gina
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date parameters on crosstab report? CW Microsoft Access Reports 1 28th Nov 2007 01:06 PM
Displaying date parameters on the report Maureen227 Microsoft Access Reports 2 12th Nov 2006 02:19 AM
Re: Date Parameters in Report Header? Allen Browne Microsoft Access Reports 3 2nd Jul 2005 04:02 PM
Report with date parameters =?Utf-8?B?QnJlbnQ=?= Microsoft Access 5 6th Oct 2004 10:37 PM
How to print date parameters on the report =?Utf-8?B?Tk5lc3Rlcg==?= Microsoft Access Reports 2 23rd Jun 2004 01:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:23 PM.