Strange event behavior?

J

Jeremy Gollehon

If you had the following code behind a form, how many times would you expect
to see the word "yo" in the Immediate window?

---------------------------------------------------
Private Sub Form_Open(Cancel As Integer)
Me.Requery
End Sub

Private Sub Form_Current()
Debug.Print "yo"
End Sub
---------------------------------------------------

I would expect it twice. Once because of the default event handling...
"When you first open a form, the following events occur in this order:
Open ? Load ? Resize ? Activate ? Current"

....and once because of the Me.Requery in the Open event. However, it's only
showing up once (after the requery). Any ideas as to why?

Thanks,
-Jeremy
 
K

Ken Snell \(MVP\)

I don't believe the Current event for the form occurs unless there is at
least one record in the query's records for the form's RecordSource.
 
K

Ken Snell \(MVP\)

Expanding on my just-sent post, what is the form's RecordSource? How did you
determine which event was causing the Current event's occurrence?
 
J

Jeremy Gollehon

Ken,
Thanks for the reply. Based on your feedback I now know what's happening.
My actual code is more complex then the sample provided. In the open event,
if the recordsource returns an empty recordset it changes the where clause
on the fly. The new recordsource returns more than zero records which
triggers the current event.

The incorrect assumption I was making is that the current event fires when a
form is open.
Access help states "This event occurs both when a form is opened and
whenever the focus leaves one record and moves to another."

It should state "This event occurs both when a form is opened (unless the
form has a Record Source which returns and empty recordset) and whenever the
focus leaves one record and moves to another."

The stranger thing to me is if a form has no record source at all the
current event will fire when the form opens.
Maybe this is a bug? Or maybe it's a bug the to not fire when there's an
empty recordset?
Nah... it's probably all by design. :)

Thanks again Ken,
Jeremy
 
K

Ken Snell \(MVP\)

Glad you found the solution. You can provide feedback to Microsoft about the
Help information (assuming that you're using ACCESS 2003) by clicking on the
Feedback buttons at the bottom of the Help information.

I'm sure that the Help writers never envisioned the situation where a form
might not have a set of records when it opens....< grin >... they shoulda
talked to a developer!
 

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