change caption of button by condition

eugz

Registered User.
Local time
Yesterday, 23:02
Joined
Aug 31, 2004
Messages
128
Hi All.
I have simple form based on Device table with 2 buttons. And would like to change caption of the buttons when user enter data to the form.
When user open form Button1 is disable and has caption Cancel.
Button2 is enable and has caption Close.
When user start enter data Button1 become enable and caption Close.
Button2 also enable but caption change to Save. How to code those buttons?
Thanks.
 
If the form is bound to a query/table then the OnDirty event of the form fires the moment the user starts to change a bound control.
 
When user open form Button1 is disable and has caption Cancel.
Why would you have a button with a caption of Cancel, but disabled so you can't use it? That makes no sense since you never seem to use it, or allow them to use it, until the form becomes dirty.
 
Thanks for replay.
I will appreciate if somebody show me how to do it.
Thanks.
 
Last edited:
Put the following code in your form's OnDirty event:
Code:
Private Sub Form_Dirty(Cancel As Integer)

Me.Button1.Enable = True
Me.Button1.Caption = "Close"
Me.Button2.Caption = "Save"

End Sub
Post back if you need additional assistance.
 
Thanks a lot for help.
That event for the form. And what code for the buttons? Also when I try enter some data buttons didn't change caption. I did exactly like you sugested.
Thanks.
 
As Bob was trying to point out, part of what we do here is offer some advice on approaches taken by the posters. Even though this is a long way from what I would recommend as a user interface, I put together this quick demo of the code I supplied. Is this some sort of class project?
 

Attachments

Users who are viewing this thread

Back
Top Bottom