On Activate Problem

J

Justin

Hi,

I'm trying to set-up a system to automatically display the proper menus to a
user depending on the user's department assignment. I have set the start-up
form for the database to be "frmMain". In the On Activate event for this
form I have placed the code to get the current user name, find the users
department assignment, open the appropriate form/menu and close the form
"frmMain". This all works except the closing of the form "frmMain". Also if
I want to requery the new form I'm openning the system just goes in a
continual loop between "frmMain" and the openned form. I've tried placing
the Close command (including from name) in the De-Active Event, but this
didn't work.

Is there something about the On Activate property that will not allow this?

Any suggestions will be appreciated. Thanks.

Justin
 
D

Dirk Goldgar

Justin said:
Hi,

I'm trying to set-up a system to automatically display the proper
menus to a user depending on the user's department assignment. I
have set the start-up form for the database to be "frmMain". In the
On Activate event for this form I have placed the code to get the
current user name, find the users department assignment, open the
appropriate form/menu and close the form "frmMain". This all works
except the closing of the form "frmMain". Also if I want to requery
the new form I'm openning the system just goes in a continual loop
between "frmMain" and the openned form. I've tried placing the Close
command (including from name) in the De-Active Event, but this didn't
work.

Is there something about the On Activate property that will not allow
this?

Any suggestions will be appreciated. Thanks.

Without seeing your code, it's hard to guess exactly what's going on. I
suppose you're aware that the form's Activate event (not "On
Activate" -- that's the name of the related property) will fire every
time the form becomes the active object. Whatever's happening is
probably related to that.

However, I'm not sure why you're using frmMain's Activate event for
this. Are you expecting the form to be activated more than once while
it remains open? The use you describe sounds more like it belongs in
the form's Open event. Do you want to actually close this form without
ever displaying it? If so, you can set up an Open event procedure for
it like this:

'----- start of code -----
Private Sub Form_Open(Cancel As Integer)

' ... code here to get current user name and
' do all related setup, including opening some
' other form ...

' Don't finish opening this form.
Cancel = True

End Sub
'----- end of code -----

If you do want to display frmMain, but only for a short period of time,
you can use the form's Timer event to close it, instead of cancelling
the Open event.
 
Top