Date Range in Report Header

hotrodsue

Registered User.
Local time
Today, 17:57
Joined
Jan 9, 2009
Messages
74
I've created a report that opens via a form that requires a Start Date and End Date. I would like the date range to show up in the report header.

I created an unbound text box in the header of the report and in the control source referred to form that generates the report as such:

=[Forms]![AskForDates]![txtStartDate]

The report opens and displays the date range in Print Preview, looks exactly how I want. However, when I print the report the unbound text box prints the following:

#Name?

Any suggestion on how to resolve this?
 
Is the form still open? It would need to be.
 
Yes, the form is still open in Print Preview. However, I noticed if I go to "Report View" or "Layout View" I see the error message #Name?
 
From the sound of it, you're closing the form after the report is previewed but before it's printed. That would cause it to display fine in preview but not when printed. Are you saying the form is open throughout?
 
That's it, the form I created is a custom dialog box. Once the Start Date and End Date are entered, I click the OK command button. The form closes and the Report opens in Report Preview, ready to print.

I just did a test where I had the report open in Report Preview. Then went back and opened my form (dialog box), entered the Start and End Date and did NOT click OK, leaving the form open.

The Report then printed with the date range rather than the error.

Do you have any suggestions how I may get this working properly?
 
Rather than closing the form in the code that opens the report, close it in the close event of the report. If it's modal and stays on top of the report, hide it in the code that opens the report and close it in the close event of the report.
 
Thank you so much for your help. I'm part of the way there. I removed the close command from the form. However, it did stay on top of the report, when the report opened - as you suspected.

You say to hide it in the code that opens the report and close it in the close event of the report. Forgive my inexperience, but would you clarify what I need to hide in the code that opens the report? Here is my code for the form.

Option Compare Database
Private Sub cmdCancel_Click()
DoCmd.Close acForm, Me.Name
End Sub
Private Sub cmdOK_Click()
If IsNull(Me!txtStartDate) Then
MsgBox "You must enter a Start Date."
Me!txtStartDate.SetFocus
ElseIf IsNull(Me!txtEndDate) Then
MsgBox "You must enter an End Date."
Me!txtEndDate.SetFocus
Else
DoCmd.OpenReport "GasolineDate", acViewPreview
DoCmd.Close acForm, Me.Name
End If
End Sub

Many thanks.
 
Try

Me.Visible = False
 
Thanks, that worked for hiding the form:

Me.Visible = False

I'm sorry, but I don't know what code to put in the close event of the report to get the form to close.

I'm pretty new, I've spent a few months self-taught with a book, and a video tutorial. Sure working hard and don't want to be a bother.

Many, many thanks for your kindness and patience.
 
No problem, and welcome to the site by the way. You actually already have it, with one tweak. Instead of:

DoCmd.Close acForm, Me.Name

use

DoCmd.Close acForm, "TheActualNameOfTheForm"
 
Try:

Code:
        DoCmd.OpenForm "AskforDates", acNormal, , , , acHidden

then

Code:
        DoCmd.OpenReport  ...

then on the report On Close if you want to the Dailog box

Code:
    DoCmd.OpenForm "AskforDates", acNormal, "", "", , acNormal

I also close the originating form last ie. after opening the report

Simon
 
No problem, and welcome to the site by the way. You actually already have it, with one tweak. Instead of:

DoCmd.Close acForm, Me.Name

use

DoCmd.Close acForm, "TheActualNameOfTheForm"

Thanks for the welcome. I've book marked the site. I think my brain is fried. :eek:

Would you believe on the report close event, I entered the following code and now I'm back to the original problem. The date is showing up with #Name? in header of report:

Private Sub Report_Close()
DoCmd.Close acForm, "AskForDates"
End Sub
 
You didn't leave that line in the report open code, did you? Post the current code for opening the report.
 
I'm missing something, perhaps a few brain cells.

Here's the code for the Form which opens the report fine:

Private Sub cmdCancel_Click()
DoCmd.Close acForm, Me.Name
End Sub
Private Sub cmdOK_Click()
If IsNull(Me!txtStartDate) Then
MsgBox "You must enter a Start Date."
Me!txtStartDate.SetFocus
ElseIf IsNull(Me!txtEndDate) Then
MsgBox "You must enter an End Date."
Me!txtEndDate.SetFocus
Else
DoCmd.OpenReport "GasolineDate", acViewPreview
Me.Visible = False
End If
End Sub

Here's the entire code for the Report (no open command, as I thought the open command was for the form only):

Private Sub Report_Close()
DoCmd.Close acForm, "AskForDates"
End Sub
 
Well, when you find yours see if mine are around anywhere. That looks like it should work. I assume that code is all in the form AskForDates. Can you post the db?
 
Brain cells, highly over-rated. Can you tell me how to post the db?
 
This worked for me. Many thanks for all the posts and ideas from everyone here.

Try:

Code:
        DoCmd.OpenForm "AskforDates", acNormal, , , , acHidden

then

Code:
        DoCmd.OpenReport  ...

then on the report On Close if you want to the Dailog box

Code:
    DoCmd.OpenForm "AskforDates", acNormal, "", "", , acNormal

I also close the originating form last ie. after opening the report

Simon
 

Users who are viewing this thread

Back
Top Bottom