Visible property of Form not working (1 Viewer)

elliotgr

Registered User.
Local time
Today, 09:51
Joined
Dec 30, 2010
Messages
67
I know this has come up before, but the suggested solutions do not work such as setting focus etc. I am using Access 2007. There was no problem doing this with Access 2003.

I need to open the form with visible set to false via VBA

Current code on the Open event is
Code:
Private Sub Form_Open(Cancel As Integer)
Forms!MyForm.Visible = False
End Sub
 

apr pillai

AWF VIP
Local time
Today, 12:21
Joined
Jan 20, 2005
Messages
735
If you are opening this form through a Command Button click Event procedure I think a better method is to try the following simple DoCmd statements to open the Form in hidden mode and to bring it into focus when needed:

To Open the Form in hidden mode:
Code:
Sub cmdOpen_Click()
   Docmd.OpenForm "MyForm",acNormal,,,,acHidden
End Sub

To make the form visible, when needed:

Code:
Sub cmdShow_Click()
    DoCmd.SelectObject acForm,"MyForm", False
End Sub
 

elliotgr

Registered User.
Local time
Today, 09:51
Joined
Dec 30, 2010
Messages
67
Hi, thanks for the repsonse.
However the form loads automaticalty when the database is opened. It is used to supply reference data, and opens another form which is the main switchboard.
I could hide the fields on the Switchboard form, but am trying to find out why I can't open the start up form as visible = false.
I even created a complete stand alone database whose only function is to open a form when starting up, but there is no way I could find to make the start up form visible = false.
MSDN help? was no use at all, as the only solution they supply is
Code:
Me.Visible = False
or
Code:
Forms!frmStartUp.visible = False
during the Open event. Neither works. No error messages are returned.
This was functionality I always used in 2003 and had no issues.
 

boblarson

Smeghead
Local time
Yesterday, 23:51
Joined
Jan 12, 2001
Messages
32,059
Are you sure that the events are firing? It could be that the VBA isn't enabled due to the database not being in a "trusted location" and the notifications (the enable button) has been turned off in the options.
 

elliotgr

Registered User.
Local time
Today, 09:51
Joined
Dec 30, 2010
Messages
67
The database is in a trusted location. I can see in the Immediates window the status change. I can make it invisible when the code runs (checked by stepping thru the code). However immediately the sub stops running, it becomes visible. I tried to set the focus to another form as well in case this was the issue. Done before and after the startup form opens. Also tried on the OnLoad event.
Note this only occurrs with a start up form. I can make any other form invisible

Even creating a test database with a single form that opens when the Access app is started results in the form becoming visible despite having the OnLoad and Open event fire off a msgbox indicating the code is running and doing the Me.visible = false or using the complete identifier for the form does not work.
 

John Big Booty

AWF VIP
Local time
Today, 16:51
Joined
Aug 29, 2005
Messages
8,263
I've had a play with with this in my Sand Box DB and it would seem that you can not set the form's Visible property to False in the On Open event, or at least the code has no effect. It also has no effect in the On Load and On Current events. I know the code is being run as I put the exact same code in all three events with break points in each. I also know that the code works as I tried it in a Command Button.

What you could do is use an AutoExec Macro to open the form using apr pillai's suggestion.
 
Last edited:

ChrisO

Registered User.
Local time
Today, 16:51
Joined
Apr 30, 2003
Messages
3,202
Try setting the form’s timer interval to 1:-

Code:
Private Sub Form_Timer()

    Me.TimerInterval = 0
    Me.Visible = False

End Sub

Chris.
 

Users who are viewing this thread

Top Bottom