Dialog Form for Date Variables Won't Close

R

Robert T

Hello:

I created a simple dialog form that accepts a Start and End Date for a
report. So far it seems to be working very well, however, the dialog form
doesn't close, it remains open on the screen. Where and how do I close the
dialog form? Is it done from the Report?

Form Name: dfrmWhatDates

Form Fields: vStartDate and vEndDate

Here is the code behind the cmdRpt box.

Private Sub cmdRpt_Click()
Dim strReport As String 'Name of report to open.
Dim strField As String 'Name of the date field.
Dim strWhere As String 'Where condition to open the Report.
Const conDateFormat = "\#mm\/dd\/yyyy\#"

strReport = "rptTSR_Classes"
strField = "Class_Date"

If IsNull(Me.vStartDate) Then
MsgBox ("Start Date is Missing")
Me.vStartDate.SetFocus
'Cancel = True
GoTo End_Sub
End If

If IsNull(Me.vEndDate) Then
MsgBox ("End Date is Missing")
Me.vEndDate.SetFocus
'Cancel = True
GoTo End_Sub
End If

If Me.vEndDate < Me.vStartDate Then
MsgBox ("The End Date cannot come before the Start Date")
Me.vEndDate.SetFocus
GoTo End_Sub
End If

strWhere = strField & " Between " & Format(Me.vStartDate, conDateFormat) _
& " And " & Format(Me.vEndDate, conDateFormat)


DoCmd.OpenReport strReport, acViewPreview, , strWhere
'DoCmd.Close
End_Sub:

End Sub
 
R

Robert T

Hi Doug:

If I remove the apostrophe in front of "DoCmd.close" the report does NOT
open and the form does NOT close.

Note:

I used another database program for many years and we closed the dialog form
from the report. I can't remember which event we used, but that worked.

Robert


:

[What happens when you remove the comment from in front of DoCmd.Close?]
 
R

Robert T

Hi Douglas:

By mistake, I put the code you suggested in the report's CLOSE event and it
worked like a charm, so I didn't even bother trying it in the report's Open
Event. Do you think it makes any difference [Open or Close event]?

Thanks so much,
Robert

[Try putting DoCmd.Close acForm, "NameOfForm" in the report's Open event.]
 
C

Corey-g via AccessMonster.com

Do you want the form to close while the report is open, or after? I think
that is the only difference, I don't think there will be any adverse effects
either way...

Robert said:
Hi Douglas:

By mistake, I put the code you suggested in the report's CLOSE event and it
worked like a charm, so I didn't even bother trying it in the report's Open
Event. Do you think it makes any difference [Open or Close event]?

Thanks so much,
Robert

[Try putting DoCmd.Close acForm, "NameOfForm" in the report's Open event.]
 
D

Douglas J. Steele

If you put it in the Open, it should disappear once the report's open. No
other difference.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top