Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 1 / January 2007

Tip: Looking for answers? Try searching our database.

OnActivate when changing RecordSource

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
G Gerard - 06 Jan 2007 17:42 GMT
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
Allen Browne - 07 Jan 2007 05:55 GMT
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.

Signature

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.

> Hello
>
[quoted text clipped - 21 lines]
> Thanks
> G Gerard
G Gerard - 09 Jan 2007 22:34 GMT
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

> 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
[quoted text clipped - 40 lines]
>> Thanks
>> G Gerard
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.