Deactivate command button by conditionaly

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
 
W

Wayne Morgan

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")
 
A

an

Ops!
Sorry.

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

Why not?
an
 
A

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
 
W

Wayne Morgan

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.
 
A

an

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
 
A

an

Sorry, Wayne Morgan.

Exactly! Work fine!
I had an incorrect line!

Thank you very much for your help!
an
 
W

Wayne Morgan

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
 
A

an

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





.
 

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

Similar Threads


Top