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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query runs before On Open Event

Status
Not open for further replies.

GPnew

Programmer
Nov 12, 2001
56
NZ
My form has a record source that is a parameter query. The "parameters" are to be obtained from a second form that is opened in on open event in the first form as follows

Private Sub Form_Open(Cancel As Integer)
On Error Resume Next
DoCmd.OpenForm "Month Report Dates", acDesign, , , , acDialog, "MonthlyBoardReport"
If Not IsLoaded("Month Report Dates") Then
Cancel = True
End If

End Sub

My problem is that the query runs before the Form_open event...I get prompted for the parameters prior the above code being called. After entering the parameters the code does get called!

Any Ideas how to fix this so the code does get called before the query running ?

Thanks

 
In stead of calling it from the on open, consider opening the other form first, populate the controls holding the parameters, then open this form and close the "Month Report Dates" form.

Though I'd also try replacing the acDesign as the view arguement with acNormal, too, and see if that makes any changes.

Roy-Vidar
 
Another way to do it is to erase the Record Source property of the main form in Design View, and have code like the following in the Month Report Dates form:
Code:
Form_AfterUpdate()
    Forms![main form name].RecordSource = "query name"
End Sub

However, I usually use Roy's method.

Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
Thanks for the replies.

A problem I have with both solutions is that I use the "Month Report Dates" form for the parameteres on a couple of reports as well ... so I don't really want to put code in it specifically in relation to the form I am trying to use now.

Incidentally "Month Report Dates" works fine for the reports (one of which uses the same record source)

Thanks
 
All right, then how about this? Erase the main form's Record Source, and add code to its Open event procedure to set the RecordSource to the query name.

Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top