Deactivate command button by conditionaly

  • Thread starter Thread starter an
  • Start date Start date
A

an

Hello!

In Access2K, is it possible "deactivate" a command button
in form, by conditionaly?
Ex:
If fieldA=Y, command button is visible;
If FieldA=N, command button is not visible.

Thanks in advance.
an
 
Yes, it is.

If Me.txtMyTextbox = "Y" Then
Me.cmdMyCommandButton.Visible = False
Else
Me.cmdMyCommandButton.Visible = True
End If

While the above is easier to read and follow, the following provides the
same logic.

Me.cmdMycommandButton.Visible = Not (Me.txtMyTextbox = "Y")
 
Ops!
Sorry.

When change the condition, different of the 1st, don't
appear the corresponding command button...

Why not?
an
 
Thank you for your replay.
Sorry for may delay, but whithout Internet...

I choosed your 2nd option:
Me.Command5.Visible = Not (Me.Situation = "Y")

I code is placed on SubForm in "On Load".

When we change to 2nd record (with "N") the command
buttons don't exchange between them, but if we change "Y"
to "N" in Table, work fine.

Thank you very much.
an
 
Move the code from the OnLoad event to the OnCurrent event. The Current
event will fire each time you move to a different record, including the move
to the first record when the form opens. You will also need to place a copy
of the code in the AfterUpdate event of the textbox so that it will run when
you change the value in the textbox.
 
Ok, work but...
with one small otherwise.
In the last record, or add new, return error, because
don't exist "Y" or "N".

Thanks
an
 
Sorry, Wayne Morgan.

Exactly! Work fine!
I had an incorrect line!

Thank you very much for your help!
an
 
I'm glad it's working for you. If, in the future, you need to adjust code to
behave differently when you're at a new record, it is fairly easy to do. You
would use an If statement to check for the new record status.

Example:
If Me.NewRecord = True Then
'do stuff here
Else
'do something else here
End If
 
Hoo!
Ok.

Many, many thanks.

Good luck!
an
-----Original Message-----
I'm glad it's working for you. If, in the future, you need to adjust code to
behave differently when you're at a new record, it is fairly easy to do. You
would use an If statement to check for the new record status.

Example:
If Me.NewRecord = True Then
'do stuff here
Else
'do something else here
End If

--
Wayne Morgan
Microsoft Access MVP





.
 
Back
Top