Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem using code to open a form, but works to open a report

Status
Not open for further replies.

Dophia

Technical User
Jul 26, 2004
263
CA
Hello: I would like to open different forms, based on dates in an unbound combo box on a different form. So, open a form to specify dates and then click to open a form with that date range of records. It is called from the form that is to open.
I currently used something I came across online, to open reports, but I can't seem to do the same thing with opening a form. What is in the following that is stopping it from working with opening a form? The result is that the it first opens the query specification. "enter Paramater Value", then opens the unbound form.

In Module:
Option Compare Database
Option Explicit
Public bInReportOpenEvent As Boolean ' Is report in the Open event?

Form where I choose dates on an unbound form:
Private Sub Form_Open(Cancel As Integer)

If Not bInReportOpenEvent Then
'If we're not called from the report
MsgBox "For use from the Statistics All Report only", vbOKOnly
Cancel = True
End If
Form_Open_Exit:
Exit Sub
End Sub

On the report that I want to open:
Private Sub Report_Open(Cancel As Integer)
' Set public variable to true to indicate that the report
' is in the Open event
bInReportOpenEvent = True

' Open FrmCrosstab2
DoCmd.OpenForm "FrmStatsAll", , , , , acDialog
'If the user closed the form (cancelled)

If Not IsFormLoaded("FrmStatsAll") Then
Cancel = True
End If
' Set public variable to false to indicate that the
' Open event is completed
bInReportOpenEvent = False
End Sub

Thank you for any help. Sophia

 
I would add some debug.print statements and/or breakpoints in the code to see what is happening. faq705-7148

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top