Having Trouble creating a hidden form (A2003)

C

Clif McIrvin

I'm stymied.

I've created an 'empty' form that I want to use to effect the OnClose
behavior of another form.

The problem I'm having is that I cannot consistently make my new form
stay quietly hidden!

My intention was to make my hidden form the "Startup Options" form, and
have it's Load Procedure hide it and open the user interface form. I
quickly discovered that sometimes the form would open hidden, and
sometimes open visible and have been completely unable to discover what
the cause might be.

Form name: "Hidden Form"
Private Sub Form_Load()
Application.Echo False, "Open Database ..."
Me.Visible = False
DoCmd.OpenForm "UI Form", , , , _
acFormReadOnly
End Sub

(In the Form_Load procedure of UI Form I turn Echo back on.)

Things I have attempted:

1. Hidden Form as the Startup Form: Hidden Form opens visible on top of
UI Form.
2. Launch Hidden Form by selecting it from the database window. It opens
visible on top of UI Form.

I attempted searching newsgroups and several Access websites but have
found no solution.

Suggestions, anyone?
 
D

Dirk Goldgar

Clif McIrvin said:
I'm stymied.

I've created an 'empty' form that I want to use to effect the OnClose
behavior of another form.

The problem I'm having is that I cannot consistently make my new form stay
quietly hidden!

My intention was to make my hidden form the "Startup Options" form, and
have it's Load Procedure hide it and open the user interface form. I
quickly discovered that sometimes the form would open hidden, and
sometimes open visible and have been completely unable to discover what
the cause might be.

Form name: "Hidden Form"
Private Sub Form_Load()
Application.Echo False, "Open Database ..."
Me.Visible = False
DoCmd.OpenForm "UI Form", , , , _
acFormReadOnly
End Sub

(In the Form_Load procedure of UI Form I turn Echo back on.)

Things I have attempted:

1. Hidden Form as the Startup Form: Hidden Form opens visible on top of
UI Form.
2. Launch Hidden Form by selecting it from the database window. It opens
visible on top of UI Form.

I attempted searching newsgroups and several Access websites but have
found no solution.

Suggestions, anyone?


Tricky, isn't it? When you tell Access to open the form at startup, it
really wants to make it visible.

I've done this using a combination of code in the form's Open event and
Timer event. Here's what I did:

+ Set the form's TimerInterval property to 1 (that is, 1 millisecond).

+ Add this code for the form's module:

'----- start of code -----
Option Compare Database
Option Explicit

' Module-level variables to hold initial dimensions of form
Dim mlngHeight As Long
Dim mlngWidth As Long

Private Sub Form_Open(Cancel As Integer)

' Save current dimensions.
mlngHeight = Me.WindowHeight
mlngWidth = Me.WindowWidth

' Make form infinitesimal so it can't be seen, even for a moment.
DoCmd.MoveSize , , 0, 0

End Sub

Private Sub Form_Timer()

' Hide the form.
Me.Visible = False

' Reset the timer interval so this event doesn't fire again.
Me.TimerInterval = 0

' Size the form back to its original dimensions.
If mlngWidth <> 0 Then
Me.InsideHeight = mlngHeight
Me.InsideWidth = mlngWidth
End If

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

That's all.
 
N

NetworkTrade

Dirk's reply is far more comprehensive......

I myself have lazy tendancies and probably would take a simplistic approach
and use a Macro for no other purpose but than to open the form; and in the
Macro one can set the form's property to hidden....

I realize that this suggestion will make many cringe.....I do believe that I
have actually done this, and it worked....but it has been many moons past and
I can't completely remember whether or not this is true....
 
C

Clif McIrvin

NetworkTrade said:
Dirk's reply is far more comprehensive......

I myself have lazy tendancies and probably would take a simplistic
approach
and use a Macro for no other purpose but than to open the form; and in
the
Macro one can set the form's property to hidden....

I realize that this suggestion will make many cringe.....I do believe
that I
have actually done this, and it worked....but it has been many moons
past and
I can't completely remember whether or not this is true....
Thanks to both of you!

I forgot to mention that I had tried setting visible to False in the
form's GotFocus procedure, as well. I'm
happy to see that your replies confirm what I was finding on my own <g>.

I'll give Dirk's method a go.

Thanks again.
 
C

Clif McIrvin

Dirk, works like a charm!

Thanks,
--clif


Dirk Goldgar said:
Tricky, isn't it? When you tell Access to open the form at startup,
it really wants to make it visible.

I've done this using a combination of code in the form's Open event
and Timer event. Here's what I did:

+ Set the form's TimerInterval property to 1 (that is, 1 millisecond).

+ Add this code for the form's module:

'----- start of code -----
Option Compare Database
Option Explicit

' Module-level variables to hold initial dimensions of form
Dim mlngHeight As Long
Dim mlngWidth As Long

Private Sub Form_Open(Cancel As Integer)

' Save current dimensions.
mlngHeight = Me.WindowHeight
mlngWidth = Me.WindowWidth

' Make form infinitesimal so it can't be seen, even for a moment.
DoCmd.MoveSize , , 0, 0

End Sub

Private Sub Form_Timer()

' Hide the form.
Me.Visible = False

' Reset the timer interval so this event doesn't fire again.
Me.TimerInterval = 0

' Size the form back to its original dimensions.
If mlngWidth <> 0 Then
Me.InsideHeight = mlngHeight
Me.InsideWidth = mlngWidth
End If

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

That's all.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

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