Change Button caption when text field "changes"

A

AnExpertNovice

There is probably an easy solution. I have just not found it yet!

txtDisabled contains the date the record was disbled. It is Enabled but
Locked. (allows copy)

cmdEnableDisable is a button used to set or clear txtDisabled. It would be
nice if it read "Disable" then txtDisabled was empty and "Enable" when
txtDisable contains a date.

Is there a easy way to detect when txtDisabled has changed or may have
changed. By "may have changed" even changing to a different record means the
buttons caption can be set after a query. I have found no text field or
form event that allows this to be done.

Thanks.
 
R

Ruskin

Try something like the following (where dteField is the name of the date
field, so you will need to replace this with txtDisabled)....

Private Sub cmdEnableDisable_Click()
If IsNull(dteField) Then
dteField = Now
cmdEnableDisable.Caption = "Disable"
Else
dteField = Null
cmdEnableDisable.Caption = "Enable"
End If
End Sub

Private Sub Form_Current()
If IsNull(dteField) Then
cmdEnableDisable.Caption = "Enable"
Else
cmdEnableDisable.Caption = "Disable"
End If
End Sub
 
A

AnExpertNovice

The problem is not that simple.
Assume that the record being viewed has a disabled date. I want the button
to read Enable.
Now, assume that the record being displayed changes (A filter button was
checked, a navigation button was clicked, the mouse wheel was turned, the
current record was deleted, a drop down box was used to select another
record.) and that the new record does not have a disabled date. Now the
button should read Disable.

The problem is there seems to be no event that is fired just because a new
record has been selected. I could just label the button Enable/Disable and
let the user figure out which is was going to do, but while simple it is not
as clean. Besides, finding a solution will help me to learn.
 
A

AnExpertNovice

never mind. The "On Current" event is what I needed.

BTW, thanks for responding!
 

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

Top