Hide or show buttons on forms based on some criteria

G

Guest

I have a form where I would like to hide or show a button based on some
criteria - eg, if the data is ready for updating, the 'update' button is
shown. Obviously I could create a separate form for each different criteria,
but I would prefer for the buttons to appear and disappear as they are
required on the one form.

Is this possible?

Thanks
Richard
 
G

Guest

Try this

Me.[Button name].Visible = (Enter here the criteria)

You can put this line in two places
1. OnCurrent event of the form, so the button will apear and disapear when
you move between records
2. On the after update event of the fields that make your criteria, so when
the values are changed the button will apear or disapear.
 
G

Guest

Ofer, i could not get your solution to work.

my button name is: NOR CERT 4
i only need to see it when the field: CERT 4
is not null.

how would you write that? my attemtps have failed. thanks..
the field is on the form and i tried the code in the OnCurrent event on the
Form.

Ofer said:
Try this

Me.[Button name].Visible = (Enter here the criteria)

You can put this line in two places
1. OnCurrent event of the form, so the button will apear and disapear when
you move between records
2. On the after update event of the fields that make your criteria, so when
the values are changed the button will apear or disapear.

--
Please respond to the group if your question been answered or not, so other
can refer to it.
Thank you and Good luck



RichardT said:
I have a form where I would like to hide or show a button based on some
criteria - eg, if the data is ready for updating, the 'update' button is
shown. Obviously I could create a separate form for each different criteria,
but I would prefer for the buttons to appear and disappear as they are
required on the one form.

Is this possible?

Thanks
Richard
 
T

TC

Put this in the form_current event:

msgbox "ISNULL = " & isnull(me![CERT 4])
me![NOR CERT 4].visible = not isnull(me![CERT 4])

The msgbox is just temporary, to make sure that the IsNull() function
is returning what you thunk it should. Remove that statement when
you've done with it.

Note: I suggest you start using some naming conventions., For example,
all command button names might start wth the prefix "cmd", all textbox
controls with "txt", and so on. You'll find your code is much easier to
read & understand, when you follow some naming conventions.

HTH,
TC (MVP Access)
http://tc2.atspace.com
 
G

Guest

is it possible to hide multiple buttons/fields in a single statement based on
one condition? or just repeat the statment several times.

me![NOR CERT 4].visible = not isnull(me![CERT 4])
me![NOR CERT 5].visible = not isnull(me![CERT 4])
me![NOR CERT 6].visible = not isnull(me![CERT 4])
 
R

Ron2005

One way to do that is:

if isnull(me![CERT 4]) then
me.[NOR CERT 4].visible = false
me.[NOR CERT 5].visible = false
me.[NOR CERT 6].visible = false
else
me.[NOR CERT 4].visible = true
me.[NOR CERT 5].visible = true
me.[NOR CERT 6].visible = true
endif

There are some snazyier ways to do this, but this may be easier to
debut 6 months from now when someone needs a change in the logic and
you almost remember everything you did in the module..
 
T

TC

Like Ron20095 said.

Or:

me.[NOR CERT 4].visible = not isnull(me![CERT 4])
me.[NOR CERT 5].visible = me.[NOR CERT 4].visible
me.[NOR CERT 6].visible = me.[NOR CERT 4].visible
- inelegant, but good when the expression is very complicated, or it
takes a noticable time to execute, and you really do not want to repeat
it.

Or other ways also!

HTH,
TC (MVP Access)
http://tc2.atspace.com
 
L

long

ni hao a !zhe shi wo men de zuo ye ..
Joe said:
is it possible to hide multiple buttons/fields in a single statement based on
one condition? or just repeat the statment several times.

me![NOR CERT 4].visible = not isnull(me![CERT 4])
me![NOR CERT 5].visible = not isnull(me![CERT 4])
me![NOR CERT 6].visible = not isnull(me![CERT 4])

TC said:
Put this in the form_current event:

msgbox "ISNULL = " & isnull(me![CERT 4])
me![NOR CERT 4].visible = not isnull(me![CERT 4])

The msgbox is just temporary, to make sure that the IsNull() function
is returning what you thunk it should. Remove that statement when
you've done with it.

Note: I suggest you start using some naming conventions., For example,
all command button names might start wth the prefix "cmd", all textbox
controls with "txt", and so on. You'll find your code is much easier to
read & understand, when you follow some naming conventions.

HTH,
TC (MVP Access)
http://tc2.atspace.com
 
S

shanshan

Joe said:
is it possible to hide multiple buttons/fields in a single statement based on
one condition? or just repeat the statment several times.

me![NOR CERT 4].visible = not isnull(me![CERT 4])
me![NOR CERT 5].visible = not isnull(me![CERT 4])
me![NOR CERT 6].visible = not isnull(me![CERT 4])

TC said:
Put this in the form_current event:

msgbox "ISNULL = " & isnull(me![CERT 4])
me![NOR CERT 4].visible = not isnull(me![CERT 4])

The msgbox is just temporary, to make sure that the IsNull() function
is returning what you thunk it should. Remove that statement when
you've done with it.

Note: I suggest you start using some naming conventions., For example,
all command button names might start wth the prefix "cmd", all textbox
controls with "txt", and so on. You'll find your code is much easier to
read & understand, when you follow some naming conventions.

HTH,
TC (MVP Access)
http://tc2.atspace.com
 

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