Button Formatting

A

albycindy

I have written code to disable a button on my form based on the value of a
check box but it keeps telling me that I have put in an Else without an If
(which is obviously there)...why?

Private Sub CarrierCheck_AfterUpdate()
If CarrierCheck.Value = True Then CmdLynx.Enabled = True
Else: Cmd Lynx.Enabled = False
End If
End Sub
 
D

Dennis

You can only have a statement on the same line as your 'then' if it is the
only statement in the if.
Make your code like this and it will work.

Private Sub CarrierCheck_AfterUpdate()
If CarrierCheck.Value = True Then
CmdLynx.Enabled = True
Else
CmdLynx.Enabled = False
End If
End Sub
 
W

Wolfgang Kais

"albycindy".

albycindy said:
I have written code to disable a button on my form based on the value
of a check box but it keeps telling me that I have put in an Else without
an If (which is obviously there)...why?

Private Sub CarrierCheck_AfterUpdate()
If CarrierCheck.Value = True Then CmdLynx.Enabled = True
Else: Cmd Lynx.Enabled = False
End If
End Sub

.... because the "If line doesn't end after the "Then". Try this:
If CarrierCheck.Value = True Then
CmdLynx.Enabled = True
Else
Cmd Lynx.Enabled = False
End If
End Sub

.... or even shorter: Cmd Lynx.Enabled = CarrierCheck
 
A

albycindy

Brilliant!! Thank you....short answers that I understand....I must be getting
there......

Thanks heaps!!
 
F

fredg

I have written code to disable a button on my form based on the value of a
check box but it keeps telling me that I have put in an Else without an If
(which is obviously there)...why?

Private Sub CarrierCheck_AfterUpdate()
If CarrierCheck.Value = True Then CmdLynx.Enabled = True
Else: Cmd Lynx.Enabled = False
End If
End Sub

Others have explained where your code went astray.
Here is a much simpler method to do what you want:

[CmdLynx].Enabled = [CarrierCheck]
 
Top