OnOpen Event and Visible Not Working

G

Guest

I have a label called "photolink" and I am setting it to visible
(Me.photolink.Visible = True) depending on certain criteria on the OnOpen
event for the form. The problem is that it's not displaying on open.

However, when I go into DESIGN View and return to FORM View the label
appears (so I know that the code is working).

Is there a way to requery the field (me.photolink.requery doesn't work) so
that it displays?

Thanks.

G
 
G

Guest

Well G....

Your code isn't working or you would have a label appear on your form.

Try a break point in your code to determine your boolean value.

Your code should look something like this...

Form_OnOpen()
me.LabelName.Visible = True/False

... your criteria, whatever it may be must result in a boolean value and
that value should be used to operate your Label.


The question is what is your trigger to achieve this value?
 
G

Guest

good point ... let me re-phrase ... why would the label appear after I simply
open the form in DESIGN View and return to FORM View?

Here's the code:
'check PHOTO
If Len(Dir("c:\" & Trim(Me.salesnumber) & ".jpg")) > 0 Then

' File exists
Me.photolink.Visible = True

Else

' File does not exist
Me.photolink.Visible = False
 
V

Van T. Dinh

It is possible that during the Open Event, the Label Control has not been
instantiated yet.

Try a later Event such as Form_Load or from your code (since you use a value
form the Current Record), use the Form_Current Event.
 
G

Guest

I agree with the last message that your code belongs in the OnCurrent event
rathr than OnOpen. However, your code should look something a little more
like this...

Sub Form_OnCurrent()

Dim bStatus as boolean
Dim sFileName as string
Dim sFilePath as string

sFileName = nz(Me.SalesNumber,"")
sFileName = Trim(sFileName)

If(len(sFileName)>0) then
sFilePath = "c:\" & sFileName & ".jpg"
bStatus = (Len(Dir(sFilePath))>0)
End If

Me.PhotoLink.Visible = bStatus

End Sub
 
G

Guest

That did it, thanks, guys!

Van T. Dinh said:
It is possible that during the Open Event, the Label Control has not been
instantiated yet.

Try a later Event such as Form_Load or from your code (since you use a value
form the Current Record), use the Form_Current Event.
 

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

Similar Threads


Top