How to tell if form is visible?

C

ctyrrell

I have a form that is usually hidden, but when I open it not hidden, I
want to do some special formatting, which would be a waste of time when
the form is hidden.
I though that I could check to see if the form was visible with the
statement:
if me.visible = true then... formatting code
however, even when the form is opened visibly, me.visible is returning
false.

I have this code in the Form_Load event. I've also tried the
Form_Activate & Form_Current event routines, to no avail. Originally I
was testing with just 'if me.visible then...' but when that didn't
work, I though maybe being more explicit was the issue.

Does anyone know the correct way for a form's code to check if the form
is visible? By the way, I am using Access 2000, Windows XP.

Thanks,
Christine
 
M

Michel Walsh

Hi,


"Me" refers to the form instance running the code. Maybe it is not the same
form, or the same instance (you can have multiple instances of the same
OBJECT running at the same time)... and it just happen that the instance you
test is visible, while the one you expect to test is hidden.


The following code works fine, displaying 10 "false" in the debug window
once we click on Command0 button:

-----------------------------------
Option Compare Database
Option Explicit
Private timeLimit As Date

Private Sub Command0_Click()
timeLimit = DateAdd("s", 10, Now)
Me.Visible = False
Me.TimerInterval = 1000
End Sub

Private Sub Form_Timer()
Debug.Print Me.Visible
If timeLimit <= Now Then
Me.TimerInterval = 0 'stop the timer
Me.Visible = True 'make the form visible again
End If
End Sub
-------------------------------



Hoping it may help,
Vanderghast, Access MVP
 

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