PC Review


Reply
Thread Tools Rate Thread

Close form from another form Please help!

 
 
stefania nj
Guest
Posts: n/a
 
      29th Sep 2010
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

 
Reply With Quote
 
 
 
 
David W. Fenton
Guest
Posts: n/a
 
      29th Sep 2010
stefania nj <(E-Mail Removed)> wrote in
news:0d240472-1e36-4de9-81d7-(E-Mail Removed)
:

> 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.

--
David W. Fenton http://www.dfenton.com/
contact via website only http://www.dfenton.com/DFA/
 
Reply With Quote
 
stefania nj
Guest
Posts: n/a
 
      30th Sep 2010
On Sep 29, 3:43*pm, "David W. Fenton" <NoEm...@SeeSignature.invalid>
wrote:
> stefania nj <stefani...@gmail.com> wrote innews:0d240472-1e36-4de9-81d7-(E-Mail Removed)
> :
>
> > *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.
>
> --
> David W. Fenton * * * * * * * * *http://www.dfenton.com/
> contact via website only * *http://www.dfenton.com/DFA/


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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook 2003 - Close parent form before opening child form Randy Microsoft Outlook Form Programming 4 26th Apr 2010 11:07 PM
Close button on a form will not close form - error 2585 - action cannot be carried out while processing a form Angus Comber Microsoft Access 2 19th Jul 2006 12:21 PM
Close form if no user action including mouse move over form. =?Utf-8?B?Um9i?= Microsoft VB .NET 6 7th Jun 2006 11:20 AM
Call data collection form from Function and wait till form close t =?Utf-8?B?ZGtlcm4=?= Microsoft Access 1 27th Feb 2006 03:36 AM
How to close parent form and not to close a child form also? Viper Microsoft C# .NET 5 15th Oct 2004 08:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:31 PM.