Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enable a button depending on a value of a field

Status
Not open for further replies.

MrMcFestoe

Technical User
Apr 6, 2003
119
0
0
GB
Hi

Can somebody help me out with this,

I have a button on a form which opens another form what i want to do is disable this button if Comms Type = audible

Is this a easy thing to do,

Thanks
 
Hi!

Perhaps in the forms on current event and the Comms Type after update event, something like:

[tt]me!cmbOpenButton.enabled=not me![Comms Type]<>&quot;audible&quot;[/tt]

HTH Roy-Vidar
 
Roy

Thanks for the quick reply trued what you suggest, and cant get it to work.

the cmbopenButton is coming up bad expression, i have tried different statments and still getting no where.

 
Hi again!

You have substituted my &quot;cmbOpenButton&quot; neme with the name of your command button? (as vieved in properties other tab, name) and the &quot;Comms Type&quot; is a valid control on the form. If not, try substituting the names, and if you're not lucky, post back with the actual names of both the button and control.

Nother thingie, VBA is case sensitive, when things are working as they should, could perhaps use also the Ucase function in the last part of the statement (NOTE - make it work without first, just checking case on the letters;-))

[tt]...Ucase(Me![Comms Type])= &quot;AUDIBLE&quot;[/tt]

HTH Roy-Vidar
 
Roy

I tried posting back last night but TT was not accepting for some reason.

Anyway

Just to refresh i have a form with a buttons on it one of the buttons opens another form this button wants to be disabled if Comms Type = Audible

I tried the following in the form OnCurrent

me!Keyholder.enabled=not me![Comms Type]<>&quot;audible&quot;

me!Keyholder Form.enabled=not me![Comms Type]<>&quot;audible&quot;

me!Keyholder_Form.enabled=not me![Comms_Type]<>&quot;audible&quot;

Even with the underscore just in case the spaces where doing something.

My main form is called CUSTOMERS the button on this form is KEYHOLDER FORM which opens KEYHOLDER form.

Thanks





 
You guys are slightly off in your syntax. To disable a button when a field's value is the string &quot;audible&quot;, use this VB code snippet:

if aField=&quot;audible&quot; then
aButton.enabled=false
end if

You may have to do a bit of experimentation to find the right place(s) for the code. I would start by putting the snippet in the form's oncurrent property and the field's onchange property.
 
OhioSteve

Is it that easy, with this is the button always enabled until the line disables it.

 
short answer:
Yes, it is that easy. I have done similar things hundreds of times.

technical answer:
This is possible because Visual Basic is an object-oriented language and the button is an object with properties. The &quot;enabled&quot; quality is a boolean property. Its default setting is true (ie, enabled).
 
Ohio,

Roys code does the same thing essentially, just with different syntax. However his has a little more functionality to it as it tests whether field is &quot;Audible&quot; or Not &quot;Audible&quot;

Roys statement is:

me!cmbOpenButton.enabled=not me![Comms Type]<>&quot;audible&quot;

The part after the = sign is a boolean expression testing the value of the field. He also placed it on the On Current event of the form and the After update of the Comms Type field.

With MrMcFestoe's field names this is what it should look like.

me![KEYHOLDER FORM].enebaled=not me![Comms Type] <> &quot;Audible&quot;

place that code in the On Current event of the form and the After Update event of the Comms Type field. That way whenever Comms Type gets changed, the button will be in the correct form(updateable or not updateable)

Your code will work and its probably what I would have done but its just not as versatile as Roy Vidar's.

HTH

Chris
 
OhioSteve,

&quot;...because Visual Basic is an object-oriented language...&quot;

Don't you mean &quot;Object Based&quot;?

Visual Basic doesn't directly support the concept of inheritance. The closest you get is Interface Inheritance using the Implements keyword.

Cheers,
Dan
 
I was pretty sure that MSAccess/VBA/VB was not case-sensitive. Can anyone else clear this up for us?

I know this is cat-skinning, but since
Code:
me![KEYHOLDER FORM].enebaled=not me![Comms Type] <> &quot;Audible&quot;
and
Code:
[KEYHOLDER FORM].enabled = ([Comms Type]=&quot;Audible&quot;)
are equivalent, isn't the second one easier to read? I always find that double-negatives (x not not equal to y) turn my brain to mush! [3eyes]


PeteJ
(Contract Code-monkey)

It's amazing how many ways there are to skin a cat
(apologies to the veggies)
 
I thought that string comparisons and whether or not is it case-sensitive is that it depends on what the comparison method is at the module level (sorry bad sentence structure).

Non-case sensitive:
Option Compare Text

Case sensitive:
Option Compare Binary

Option Compare Database - i'm not sure how this differs from Option Compare Text

Cheers,
Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top