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

OnActivate when changing RecordSource

P: n/a
Hello

I have noticed that whenever I set a form's RecordSource property
in code it launches the form's OnActivate event.

In one of my application I set a form's RecordSource to zero lenght string
during the form's OnClose event

Private Sub Form_Close()

Me!RecordSource = ""

End Sub

On some computers setting the RecordSource during the OnClose event
calls the OnActivate event of that form and causes errors since some of the
code in the
OnActivate refers to controls and subforms that are now closed.

Any thought on this?

Why is it not happening on all computers?
Thanks
G Gerard
Jan 6 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Did you have a reason for setting the form's RecordSource in its Close
event? Since the form is closing anyway, it does not seem like a useful
thing to do, and yes, it can have undesirable side effects.

Perhaps you are trying to avoid the situation where users are changing to
design view and saving the RecordSource so it loads wrongly next time? If
so, perhaps you could use code in the Open event of the form to initialize
the form correctly instead of trying to reset it in Form_Close.

A nasty side effect of setting the form's RecordSource is that it becomes
unbound. Then every bound control is going to generate an error (or perhaps
a parameter request.) You really don't want to do that! To avoid that, you
could set the RecordSource so it has all fields but no records, e.g.:
SELECT * FROM Table1 WHERE (False);
I sometimes do that in Form_Open, but it still makes no sense to me in
Form_Close.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"G Gerard" <gg*****@nbnet.nb.cawrote in message
news:9c*******************@ursa-nb00s0.nbnet.nb.ca...
Hello

I have noticed that whenever I set a form's RecordSource property
in code it launches the form's OnActivate event.

In one of my application I set a form's RecordSource to zero lenght string
during the form's OnClose event

Private Sub Form_Close()

Me!RecordSource = ""

End Sub

On some computers setting the RecordSource during the OnClose event
calls the OnActivate event of that form and causes errors since some of
the code in the
OnActivate refers to controls and subforms that are now closed.

Any thought on this?

Why is it not happening on all computers?
Thanks
G Gerard
Jan 7 '07 #2

P: n/a
Hello Allen

Thank you for your reply

The reason I am setting RecordSource during the OnClose event
is so I can delete the temporary table I have created (in another mdb)
during the OnOpen event of the form to which the form is then bound.

Itís a long explanation why Iím doing this but in short itís to give the
user the option of saving or not saving the changes made when closing the
form
while trying to avoid bloating of my main mdb on a multi user application.
(with my knowledge of Access thatís the best way I have managed to do this)

I didnít think that unbounding the form during the OnClose would create any
problem since at this point the records from the temporary table have been
copied to a main table and the form is an instance.

I will change the RecordSource to (SELECT * FROM Table1 WHERE (False);)
instead of zero length string; it makes a lot more sense.

Thanks
G Gerard

"Allen Browne" <Al*********@SeeSig.Invalidwrote in message
news:45***********************@per-qv1-newsreader-01.iinet.net.au...
Did you have a reason for setting the form's RecordSource in its Close
event? Since the form is closing anyway, it does not seem like a useful
thing to do, and yes, it can have undesirable side effects.

Perhaps you are trying to avoid the situation where users are changing to
design view and saving the RecordSource so it loads wrongly next time? If
so, perhaps you could use code in the Open event of the form to initialize
the form correctly instead of trying to reset it in Form_Close.

A nasty side effect of setting the form's RecordSource is that it becomes
unbound. Then every bound control is going to generate an error (or
perhaps a parameter request.) You really don't want to do that! To avoid
that, you could set the RecordSource so it has all fields but no records,
e.g.:
SELECT * FROM Table1 WHERE (False);
I sometimes do that in Form_Open, but it still makes no sense to me in
Form_Close.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"G Gerard" <gg*****@nbnet.nb.cawrote in message
news:9c*******************@ursa-nb00s0.nbnet.nb.ca...
>Hello

I have noticed that whenever I set a form's RecordSource property
in code it launches the form's OnActivate event.

In one of my application I set a form's RecordSource to zero lenght
string
during the form's OnClose event

Private Sub Form_Close()

Me!RecordSource = ""

End Sub

On some computers setting the RecordSource during the OnClose event
calls the OnActivate event of that form and causes errors since some of
the code in the
OnActivate refers to controls and subforms that are now closed.

Any thought on this?

Why is it not happening on all computers?
Thanks
G Gerard

Jan 9 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.