show hide command button depending on a value

C

CarWashMike

Hi
I have a list of jobs outstanding dispayed on a form based on a query
listing the jobs. The from view is set to continuous forms, the detail
section is where the data is shown similar to dataseet view. I have a
command button in the detail section which opens another form to display
additional information. I only want the user to see the command button if
there is any additional information to be seen. I have a control on the form
which shows the number of records (if any) there are so I though I could say
If me.TheControlValue > 0 Then me.CommandButton.Visible = True End If. I put
this sub in the on current event of the form but the button is visble for
every record if one record satisfies the If statement. Any advice would be
great
Mike
 
S

Stuart McCall

CarWashMike said:
Hi
I have a list of jobs outstanding dispayed on a form based on a query
listing the jobs. The from view is set to continuous forms, the detail
section is where the data is shown similar to dataseet view. I have a
command button in the detail section which opens another form to display
additional information. I only want the user to see the command button if
there is any additional information to be seen. I have a control on the
form
which shows the number of records (if any) there are so I though I could
say
If me.TheControlValue > 0 Then me.CommandButton.Visible = True End If. I
put
this sub in the on current event of the form but the button is visble for
every record if one record satisfies the If statement. Any advice would be
great
Mike

If you're going to use the construct:

If <some condition> Then CommandButton.Enabled = True

then you must have a corresponding CommandButton.Enabled = False elsewhere.

If however you code it like this:

CommandButton.Enabled = (me.TheControlValue > 0)

it will cover both cases. The part between the parens is evaluated as an
expression returning True or False.
 
C

CarWashMike

thanks for the tip, I tried it out but I still have the problem that if I
click on one record on the form that give me the answer "True" (ie the
control >0, ) then the command button is visible on all the forms (it is
continuous forms). If I can use conditional fomatting on controls on the from
and that is different for each one but I cant use conditional fromatting on
the command button.
 
S

Stuart McCall

CarWashMike said:
thanks for the tip, I tried it out but I still have the problem that if I
click on one record on the form that give me the answer "True" (ie the
control >0, ) then the command button is visible on all the forms (it is
continuous forms). If I can use conditional fomatting on controls on the
from
and that is different for each one but I cant use conditional fromatting
on
the command button.

Ah, continuous form. No wonder you can't make it work. On a continuous form,
all the detail section rows are clones of the first one, so whatever changes
you make to visibility (or just about anything else) will be repeated for
the whole dataset. No way around this one (AFAIK).
 

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