By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,506 Members | 2,282 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,506 IT Pros & Developers. It's quick & easy.

When does Does "On Open" execute?

P: n/a
Hi:

Does "On Open" code execute before or after related data is loaded? I want to test before
the form appears on the screen to see if there is any data in the queryresult, and if
there is not then I want to close the form unseen by the end user.

Regards

John baker
Nov 12 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
John,

You can do it like this in the OnOpen event of the form:

Dim Rst As DAO.Recordset
Set Rst = Me.Recordsetclone
If Rst.Recordcount = 0 Then
MsgBox "There Is No Data In The Query Result"
Cancel = True
End If
Rst.Close
Set Rst = Nothing
--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com
"John Baker" <Ba******@Verizon.net> wrote in message
news:7p********************************@4ax.com...
Hi:

Does "On Open" code execute before or after related data is loaded? I want to test before the form appears on the screen to see if there is any data in the queryresult, and if there is not then I want to close the form unseen by the end user.

Regards

John baker

Nov 12 '05 #2

P: n/a
After.

If the Form's RecordSource is set in the Design of the Form, the Form's
Recordset IS available in the Form_Open Event.

--
HTH
Van T. Dinh
MVP (Access)

"John Baker" <Ba******@Verizon.net> wrote in message
news:7p********************************@4ax.com...
Hi:

Does "On Open" code execute before or after related data is loaded? I want to test before the form appears on the screen to see if there is any data in the queryresult, and if there is not then I want to close the form unseen by the end user.

Regards

John baker

Nov 12 '05 #3

P: n/a
Remember it this way ...

you can't load the washing machine until you open it

--

Danny J. Lesandrini
dl*********@hotmail.com
http://amazecreations.com/datafast
"John Baker" <Ba******@Verizon.net> wrote in message news:7p********************************@4ax.com...
Hi:

Does "On Open" code execute before or after related data is loaded? I want to test before
the form appears on the screen to see if there is any data in the queryresult, and if
there is not then I want to close the form unseen by the end user.

Regards

John baker

Nov 12 '05 #4

P: n/a
TC
In addition to what the others have said, remember that if you close the
form by cancelling the Open event, the caller will get a runtime error - so
you will have to code for that. The alternative is to close it using
DoCmd.Close - then the runtime error does not occur. Can't remember if you
can do that from the Open event, or whether you have to wait for Load.

HTH,
TC
"John Baker" <Ba******@Verizon.net> wrote in message
news:7p********************************@4ax.com...
Hi:

Does "On Open" code execute before or after related data is loaded? I want to test before the form appears on the screen to see if there is any data in the queryresult, and if there is not then I want to close the form unseen by the end user.

Regards

John baker

Nov 12 '05 #5

P: n/a
you can also use the onopen event to set the recordsource to a different
record source. for example, if there are many "code" tables, each with 2
columns, then in OnOpen decide which recordsource is needed and set it, the
form or report will then execute using the new recordsource.

John Bickmore
www.BicycleCam.com
www.Feed-Zone.com

"TC" <a@b.c.d> wrote in message news:1071808235.577113@teuthos...
In addition to what the others have said, remember that if you close the
form by cancelling the Open event, the caller will get a runtime error - so you will have to code for that. The alternative is to close it using
DoCmd.Close - then the runtime error does not occur. Can't remember if you
can do that from the Open event, or whether you have to wait for Load.

HTH,
TC
"John Baker" <Ba******@Verizon.net> wrote in message
news:7p********************************@4ax.com...
Hi:

Does "On Open" code execute before or after related data is loaded? I

want to test before
the form appears on the screen to see if there is any data in the

queryresult, and if
there is not then I want to close the form unseen by the end user.

Regards

John baker


Nov 12 '05 #6

P: n/a
Thank you all very much. Your responses and thoughts were very helpful.

Regards

John Baker
Nov 12 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.