Make a label visible with if statement

C

Chris641

G'day,

Just wondering if it was possible to make a label on a form/report visible
through an if then statement?

For example,

I want to make Label210 visible if the field named "Supplier No" is equal to
1, 2 or 3, is there any way to write this into the form code?

Cheers,

Chris
 
T

Tom van Stiphout

On Tue, 17 Feb 2009 23:49:01 -0800, Chris641

if Me![Supplier No] = 1 or Me![Supplier No] = 2 or Me![Supplier No] =
3 then
Me.Label210.Visible = True
else
Me.Label210.Visible = False
end if

Or you could use a more compact one-liner:
Me.Label210.Visible = (Me![Supplier No]>=1 and Me![Supplier No] <= 3)

Where you put this depends a bit on your exact situation; perhaps in
the Form_Load or Form_Current event.

-Tom.
Microsoft Access MVP
 
C

Chris641

Thanks,

I've put this in my code..

Private Sub Form_Current()
If Me![Supplier No] = 1 or Me![Supplier No] = 2 or Me![Supplier No] =
3 then
Me.Label210.Visible = True
Else
Me.Label210.Visible = False
End If

End Sub

I assume im supposed to replace "me" with something? and also im assuming
there is some syntax in there that is wrong. Suggestions?

Cheers,

Chris

Tom van Stiphout said:
On Tue, 17 Feb 2009 23:49:01 -0800, Chris641

if Me![Supplier No] = 1 or Me![Supplier No] = 2 or Me![Supplier No] =
3 then
Me.Label210.Visible = True
else
Me.Label210.Visible = False
end if

Or you could use a more compact one-liner:
Me.Label210.Visible = (Me![Supplier No]>=1 and Me![Supplier No] <= 3)

Where you put this depends a bit on your exact situation; perhaps in
the Form_Load or Form_Current event.

-Tom.
Microsoft Access MVP

G'day,

Just wondering if it was possible to make a label on a form/report visible
through an if then statement?

For example,

I want to make Label210 visible if the field named "Supplier No" is equal to
1, 2 or 3, is there any way to write this into the form code?

Cheers,

Chris
 
B

BruceM

You do not need to replace Me with anything. Me means that what follows is
a member of a collection. Collections can be controls, properties, and
quite a number of things. The use of the bang (!) or dot has been widely
discussed. In many cases they are interchangeable. More here:
http://my.advisor.com/doc/05352

I take it the code does not work as expected. Note that it will work only
when you go to a record.

Assuming [Supplier No] is a field, Label210 is the correct name of the label
you wish to hide, and both are spelled correctly, the code should work as
long as [Supplier No] is a number rather than text. Go to table design view
to be sure about that.

Try adding this temporary line of code above the code you now have in the
Current event:
MsgBox Me.SupplierNo

This will tell you the value of SupplierNo for that record, in case it is
not already clear. Even if it seems clear, there is no harm to verifying
the information.

Chris641 said:
Thanks,

I've put this in my code..

Private Sub Form_Current()
If Me![Supplier No] = 1 or Me![Supplier No] = 2 or Me![Supplier No] =
3 then
Me.Label210.Visible = True
Else
Me.Label210.Visible = False
End If

End Sub

I assume im supposed to replace "me" with something? and also im assuming
there is some syntax in there that is wrong. Suggestions?

Cheers,

Chris

Tom van Stiphout said:
On Tue, 17 Feb 2009 23:49:01 -0800, Chris641

if Me![Supplier No] = 1 or Me![Supplier No] = 2 or Me![Supplier No] =
3 then
Me.Label210.Visible = True
else
Me.Label210.Visible = False
end if

Or you could use a more compact one-liner:
Me.Label210.Visible = (Me![Supplier No]>=1 and Me![Supplier No] <= 3)

Where you put this depends a bit on your exact situation; perhaps in
the Form_Load or Form_Current event.

-Tom.
Microsoft Access MVP

G'day,

Just wondering if it was possible to make a label on a form/report
visible
through an if then statement?

For example,

I want to make Label210 visible if the field named "Supplier No" is
equal to
1, 2 or 3, is there any way to write this into the form code?

Cheers,

Chris
 

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