Close form from another form Please help!

S

stefania nj

Hi,
I've been struggling with this all morning and can't find an event.
I am building a questionnaire management system.

The main menu (frmMain) shows the logged in user which databases he/
she has access to.
From there they can click on the icon of the database they want to
enter and the main menu for that database (frmDatabase) will display.
All this works great.

However the users that have only one database they want to skip the
opening form (frmMain) and go directly to the database menu
(frmDatabase).

in the current event of frmMain I have the following code:
if the number of databases associated with the user is 1 opens the
frmDatabase

Private Sub Form_Current()


If u.dbCount = 1 Then

DoCmd.OpenForm "frmDatabase"
Else
DoCmd.Maximize
End If

End Sub

This works fine.

What does not work is the following
on the open event of frmDatabase I have the following code

Private Sub Form_Open(Cancel As Integer)

If u.dbCount = 1 Then
DoCmd.Close , "frmMain"
End If

end sub

Which does not work, Why. I tried on all possible for events even in
frmMain.

what happens is that the frmMain is displayed no matter what. How can
achieve my goal?

frmMain is fired on the application start-up event.

Thank you,

Stefania
PS I am using Access 2003
 
D

David W. Fenton

:
If u.dbCount = 1 Then
DoCmd.Close , "frmMain"
End If

What about

DoCmd.Close acForm, “frmMain”

It shouldn’t be required to specify the default argument (acForm is
the default), but maybe it makes a difference in the context in
which you’re doing this.

One thought about something that’s not clear. If the form you’re
running the above code in was called from frmMain, it may be that
you can’t close the calling form.

Going back to your other routine:

If u.dbCount = 1 Then
DoCmd.OpenForm "frmDatabase"
Else
DoCmd.Maximize
End If

....if that’s running in frmMain, you might do this:

If u.dbCount = 1 Then
DoCmd.OpenForm "frmDatabase"
DoCmd.Close acForm, Me.Name
Else
DoCmd.Maximize
End If

....instead of in the OnOpen event of frmDatabase. That way you
elminate any problems caused by closing the calling form.
 
S

stefania nj

What about

  DoCmd.Close acForm, “frmMain”

It shouldn’t be required to specify the default argument (acForm is
the default), but maybe it makes a difference in the context in
which you’re doing this.

One thought about something that’s not clear. If the form you’re
running the above code in was called from frmMain, it may be that
you can’t close the calling form.

Going back to your other routine:

   If u.dbCount = 1 Then
      DoCmd.OpenForm "frmDatabase"
   Else
      DoCmd.Maximize
   End If

...if that’s running in frmMain, you might do this:

   If u.dbCount = 1 Then
      DoCmd.OpenForm "frmDatabase"
      DoCmd.Close acForm, Me.Name
   Else
      DoCmd.Maximize
   End If

...instead of in the OnOpen event of frmDatabase. That way you
elminate any problems caused by closing the calling form.

David,
it worked on the load event of frmMain.
I was sure I tried it before posting. But I guess I did not. Some days
I just can't get it right!
Again, Thank you. Stefania
 

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