condition for visible or not

Real Wally

Registered User.
Local time
Today, 00:04
Joined
Jan 28, 2003
Messages
107
Hi,

I have a form with a button that I'd like to be visible or not depending on the text in a field on that form.

I only want the button to be visible when the field txtwhere on the form reads EP.

This doesn't work:

If me.txtwhere.txt = ep then
me.btnShow.visible = true
else
me.btnShow.visible = false
end if

What does?

Thanks,

Wally
 
Code:
Me.btnShow.Visible = IIf(Me.txtWhere = "EP", True, False)
 
I don't think I've ever received a swifter response and, more importantly, the answer is 100% correct too!

Thanks Rich
 
And another one, almost equally fast! and that one works just as well (i.e. don't notice a difference)

Are you guys competing:p

Is there an advantage of one over the other?

Thanks again.
 
No real difference, Mile-o-phile's is neater (and looks more impressive from a coding point of view), Rich's is a bit longer but is probably easier to understand by someone new to vba.

The only difference may be speed but with a single execution you won't notice a difference.
 
Here it is again: ;)

Code:
Me.btnShow.Visible = Not (Me.txtWhere = "EP")
 
Again?

Are you trying to get ahead of Rich (# postings) by posting same code twice?;)
 
'on current' of your form

Open form in design view
open properties
open code of 'on current
put your code there
save

and that's it!!

Good luck

Walter
 
can't work

I have a text box which used for input discharge date, and the format is "date", I write in "form_current :

If me.txtdischarge = "" then
me.cmdArchive.visible = False
Else
me.cmdArchive.visible = True
End If

what's wrong ?

And, what is the meaning of "me" ?

Does it represent the name of the form or should I use the orginal name of the form ?
 
Code:
If IsNull(Me.txtDischarge) Then
    Me.cmdArchive.Visible = False
Else
    Me.cmdArchive.Visible = True
End If




As for what's Me mean..

Me. refers to the Class.
A form's module is a Class module in which we put events, subs, functions, and properties.
The Me. disambiguates what we are referring to within the form.

It's too much to explain so take it as meaning the Current Form in which the code is written. You can't use Me in a standalone module.
 
Re: can't work

ckleung said:

And, what is the meaning of "me" ?

I suppose you want to make the button invisible when there is a date in your txtdischarge field and to have the button visible when the field is empty?

This is a code that'll do the trick:

If IsNull(txtdischarge) Then
Me.cmdArchive.Visible = True
Else
Me.cmdArchive.Visible = False
End If
 
Thanks a lot !!!

It works, really thanks for all of you. So quick response ! :)
 

Users who are viewing this thread

Back
Top Bottom