469,351 Members | 1,769 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,351 developers. It's quick & easy.

How to make a button in/visible depending on a control's value?

sueb
379 256MB
I have a form (which is used as a Continuous subform) that has a button on it that calls up a separate, more detailed form for the the particular record's. However, I want that button to appear only when the Account Number in the subform actually has a value, so I was hoping that it would be visible in all the forms that were displaying an existing record, and not visible in the "*" form (the "add" instance, at the bottom of the series of forms).

Possible?
May 19 '11 #1

✓ answered by Stewart Ross

Hi again Sue. You can use your continuous form's On Current event to set the state of your control's visible property as follows:

Expand|Select|Wrap|Line Numbers
  1. Me![your button control name].Visible = Not(Me.NewRecord)
The NewRecord property of the form is only true when you are on a new record - in which case the On Current event would set the control not to be visible. On every existing record the NewRecord property is false, so the control would be visible.

A caution: if your control is on the detail section of your continuous form (i.e. it is on each record) this approach will not work as you expect, because Access uses a single control instance repeated over all the rows displayed - so the control will literally be removed or made visible again on all the rows of your continuous form simultaneously.

-Stewart

8 10932
Stewart Ross
2,545 Expert Mod 2GB
Hi again Sue. You can use your continuous form's On Current event to set the state of your control's visible property as follows:

Expand|Select|Wrap|Line Numbers
  1. Me![your button control name].Visible = Not(Me.NewRecord)
The NewRecord property of the form is only true when you are on a new record - in which case the On Current event would set the control not to be visible. On every existing record the NewRecord property is false, so the control would be visible.

A caution: if your control is on the detail section of your continuous form (i.e. it is on each record) this approach will not work as you expect, because Access uses a single control instance repeated over all the rows displayed - so the control will literally be removed or made visible again on all the rows of your continuous form simultaneously.

-Stewart
May 19 '11 #2
sueb
379 256MB
Ah, so it sounds like I can't get what I want, which is to have the button not visible until the user has actually created the new record.

Well, thanks for this very complete explanation, Stewart! It may very well come in handy in a future instance.
May 19 '11 #3
One note on this - you CAN specify the control for the current record in the detail section of a continuous form.

Expand|Select|Wrap|Line Numbers
  1. Private Sub ShowHide()
  2.      'Make sure looking at correct record of course..
  3.      DoCmd.RunCommand acCmdSelectRecord
  4.      MyButton.Visible = Not(Me.NewRecord)
  5. End Sub
That part of selecting the record may not be correct, I forget, and don't have my examples in front of me at the moment.
May 19 '11 #4
sueb
379 256MB
kjv 1611, so where would this go? I mean, what event for the Detail? Or, I guess, how would this get activated?
May 19 '11 #5
Whichever code you're using to set the control to visible/invisible.

The "Detail" we're talking about is the Detail section of the form. On a continuous form, the detail section is where the changing list of records is listed. So if you have 100 records, you may have 10 of them on the form at a time, for instance.

Post back to acknowledge whether that makes sense to you or not. I may not be on here much longer - at least for this weekend.
May 19 '11 #6
sueb
379 256MB
But it has to go in an event, right? I sort of tried some stuff in the On Open and On Load events, but what I was trying didn't really work.
May 19 '11 #7
NeoPa
32,184 Expert Mod 16PB
I can only assume kjv1611 is confusing what has been said. My best guess is that they're saying that access to the current record is possible (which is correct), but the point here appears to have been missed, which is that whenever the control is updated to reflect the current record, all the instances of the control on the form reflect that update. Essentially Stewart is absolutely correct in every detail (which will be no surprise to any that know him - a bit of a class swot :-D). More explanation on this subject can be found at Why Values in Unbound Form Controls do not Persist.
May 19 '11 #8
sueb
379 256MB
Thanks, NeoPa! (hmmm... it says i need 40 characters)
May 19 '11 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

9 posts views Thread by brian4cards | last post: by
1 post views Thread by Imran Aziz | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.