473,396 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 11947
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,556 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

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

Similar topics

9
by: brian4cards | last post by:
http://www.igearonline.com/subscribe/admin.asp I created a table that is filled with database records. On each row of the table I have a delete submit button to delete that record. I need to...
1
by: PCB | last post by:
Hi all, Not sure if this is possible, but can I change the controls of a command button on a per record bases in a subform. In my case, I would like to make a command button visible only if...
7
by: Dave | last post by:
I have a button on Form1 that hides the form and displays Form2: Form2 myForm2 = new Form2(); myForm2.Show(); this.Hide(); After I do some work in Form2 I want to close it and redisplay...
2
by: jayuya | last post by:
How can i check in java script if a asp.net radio button list server control is selected? I have some custom javascript function in the client side that needs to run but I don't see the way to...
1
by: Imran Aziz | last post by:
Hello All, I have an asp:linkbutton in a repeater control, what I want to do is when someone clicks the link button I should get a value for the link button, and accordingly do some action. How...
4
by: riteshjain82 | last post by:
Hi, I am maintaining a site which is written in ASP. Now i have to create some new pages. In one page we have a table with many rows. Now, I want to enable or disable(showing and hiding also) 2...
1
by: keithb | last post by:
I have a GridView control that has a delete button (hyperlink) in one column. The datasource table contains a column that has a true/false indicator showing whether or not the record can be...
5
by: Rex | last post by:
Hi, I want to change a value in one table depending on the value(s) in another table. I am trying to achieve this in a form. to elaborate I have a many-to-many relationship between tables...
5
by: Doogie | last post by:
Hi, I am trying to access the visible property of an ASP button inside javascript to no avail. Here's what my button control looks like: <asp:Button id="btnAcceptTrips" name="btnAcceptTrips"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.