 |
| Access VBA Discuss using VBA for Access programming. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

August 29th, 2005, 07:37 PM
|
|
Authorized User
|
|
Join Date: Feb 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Control button caption and visible property
Hi,
This is a two part question:
1) I have a continuous form that is a result of several queries. I would like to add a control button that opens a specific form (that part I have no problem with), but I want the caption to be the value of one of the query fields. I tried to right-click on the said field (text box) to replace it with a control button, but it doesn't allow me to do it. How can I go about this.
2) If the value of the text box is null, I don't want the control button to be visible.
Thank you
Chantal
|
|

August 30th, 2005, 07:27 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
2. Set the visible property of the button to No.
Put this code on the Form's On Current event:
'-----
If IsNull(Me.Textbox) Then
Me.btnButton.Visible = False
Else
Me.btnButton.Visible = True
End If
mmcdonal
|
|

August 30th, 2005, 07:33 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
1. Add the button to the form in Design view. This button will show up in each section of the continuous form. Leave the caption blank
On the form's On Current event, put this code:
'----------
Me.btnYourButton.Caption = Me.txtYourTextField
'----------
This will put the value of the text field as the button's caption.
Set the Visible property of the field to No and leave it on the form.
HTH
mmcdonal
|
|

August 30th, 2005, 07:35 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
That is, set the vsible property of the text field to No and leave it on the form.
mmcdonal
|
|

September 5th, 2005, 08:51 AM
|
|
Authorized User
|
|
Join Date: Feb 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
This works partially. All 125 records of the continuous form have the same button with the same caption i.e. the value of the record that has the focus (for example 9). Hence, when the focus goes to another record, all 125 buttons' caption change to 5. With the next record, the buttons are all invisible, etc...
Do you know how I can fix this ?
|
|

September 7th, 2005, 07:32 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
I would not have the caption be dynamic then. Why do you need the caption to have a field value on it. Buttons generally have captions that explain their function, not the value being passed.
mmcdonal
|
|

September 9th, 2005, 10:59 AM
|
|
Authorized User
|
|
Join Date: Feb 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
To save some space on the form... right now, i have a text field with the value (for example = 5) and a control button right next to it, to open a form that displays the "5" records...
|
|

September 9th, 2005, 11:14 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
But you can do this without changing the caption each time the value in the text field changes.
Just put the button next to the field and have a caption that works for all values.
For example, I have a form where users can look for a customer in the database, and then click a button that opens a form that displays the customer data. The label above the text box says "Find a Customer Last Name, First Name" then there is a button below the text box that says "View this Customer's data"
The user knows by this that they have to select a customer first and then click the button to see the data.
You can also check the value in the text box and do a constraint if the value is wrong.
In my case, the field is a look up to the customer table. So if the field is null (IsNull) then the user is prompted to enter a name and the action is cancelled.
HTH
mmcdonal
|
|
 |