Make button enabled only when data exists

  • Thread starter serviceman via AccessMonster.com
  • Start date
S

serviceman via AccessMonster.com

Me again!
i have a form with 2 subforms on it. One of the subforms is a continuous form
that lists all of the students added to a schedule. There is a button next to
each record that opens a small form with a COMMENTS field on it. What I would
like to do is have the button disabled unless there is something in the
COMMENTS field. Any idea about how to do this?
Thanks,
Andy
 
J

John Vinson

Me again!
i have a form with 2 subforms on it. One of the subforms is a continuous form
that lists all of the students added to a schedule. There is a button next to
each record that opens a small form with a COMMENTS field on it. What I would
like to do is have the button disabled unless there is something in the
COMMENTS field. Any idea about how to do this?
Thanks,
Andy

Use the form's Current event, *and* the Comments field's AfterUpdate
event:

Me!cmdMyButton.Enabled = Not IsNull(Me!Comments)


John W. Vinson[MVP]
 
S

serviceman via AccessMonster.com

Hey John,
I tired what you suggested, but I think I am missing something or I'm not
clear on what I'm looking to do. When I put your code in either ALL of the
notes buttons are active or ALL of the notes buttons are inactive; I'm trying
to get it so when the user sees the list of students in the continuous form
the button will be active only for those students that have comment records.
Perhaps I am putting your code in the wrong places?
Andy

John said:
Me again!
i have a form with 2 subforms on it. One of the subforms is a continuous form
[quoted text clipped - 4 lines]
Thanks,
Andy

Use the form's Current event, *and* the Comments field's AfterUpdate
event:

Me!cmdMyButton.Enabled = Not IsNull(Me!Comments)

John W. Vinson[MVP]
 
J

John Vinson

Hey John,
I tired what you suggested, but I think I am missing something or I'm not
clear on what I'm looking to do. When I put your code in either ALL of the
notes buttons are active or ALL of the notes buttons are inactive; I'm trying
to get it so when the user sees the list of students in the continuous form
the button will be active only for those students that have comment records.
Perhaps I am putting your code in the wrong places?

Whoo... I must have been really sleepy when I posted that; my advice
was simply wrong. Sorry!

A Continuous form doesn't really have separate controls for each
record. It has ONE command button, displayed many times - so when you
change its properties, all instances of it change.

The solution is not to use code as I suggested, but (with AccessXP or
later) to use Conditional Formatting. Select the command button, and
use the Format... Conditional Formatting menu option. You can set the
condition to an expression checking if the field is NULL and enable or
disable the control in that way.

John W. Vinson[MVP]
 
S

serviceman via AccessMonster.com

This is too funny!! I went out and got myself a humongus cup of coffee
because I too was feeling sleepy... came back, looked at it again and thought
to myself "I wonder if conditional formatting will work?" YES IT DOES!! I
already had it done by the time I got your response...
SO,
Go get yourself a cup o' joe and have yourself a great weekend! Thanks for
the advice!
Andy

John said:
Hey John,
I tired what you suggested, but I think I am missing something or I'm not
[quoted text clipped - 3 lines]
the button will be active only for those students that have comment records.
Perhaps I am putting your code in the wrong places?

Whoo... I must have been really sleepy when I posted that; my advice
was simply wrong. Sorry!

A Continuous form doesn't really have separate controls for each
record. It has ONE command button, displayed many times - so when you
change its properties, all instances of it change.

The solution is not to use code as I suggested, but (with AccessXP or
later) to use Conditional Formatting. Select the command button, and
use the Format... Conditional Formatting menu option. You can set the
condition to an expression checking if the field is NULL and enable or
disable the control in that way.

John W. Vinson[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

Top