how do you set a condition on command button enablement?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to disable command button when there are no records in a subform,
but the conditional formatting option on the format menu is disabled when I
select the command button.
 
you can do it with some VBA code. where is the command button located - on
the main form? or on the subform?

hth
 
Tina is correct.
You will want to look into the VBA code.

On your main form, you can add an event - the one you are looking for is the
OnCurrent event. Everytime you click the record navigator, whatever code
located in the OnCurrent section will be run.

The thing you want to do within this section will be to "look" at the field
in the subform to see if data exists. It would look similar to this:

If SubformName.Control = "" or (IsNull(SubformName.Control)) Then
me.commandbuttonName.enable = False
Else
me.commandbuttonName.enable = True
End if

Obviously you will need to plug in your Sub-forms name and the control's
name as well. I use this quite a bit, but I haven't used it to reference a
control on a subform, but I know it will work for you.
If you haven't used VBA before I suggest giving it a good look. You have a
lot more capabilities doing validation and other fun things.
HTH

JB
 
Back
Top