 |
| Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access 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
|
|
|
|

September 28th, 2007, 09:44 AM
|
|
Authorized User
|
|
Join Date: Sep 2007
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
invalid reference to property
Hi All,
I've been using Access with SQl for database deign and development but i'm very new to designing forms and programming and need ur help.
I have designed a form with an Option group on it. It has 6 options. What i am trying to do is when the user selects an option a particular text box and a command button are displayed (which are otherwise invisible). I am using a select case to do it. so far i have -
Private Sub OptionGroup_Click()
Select Case Me![OptionGroup]
Case 1
Textbox1.IsVisible = True
Case 2
....
End Select
End Sub
Do i need to add anything somewhere else ? (i get the error - u entered an expression that has an invalid reference to property invisible).
Is select case a good way to do this ?
Thanks for help.
|
|

September 28th, 2007, 09:55 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
Select is fine.
This:
Textbox1.IsVisible = True
Should be this:
Me.Textbox1.Visible = True
You may also want to add this:
Private Sub OptionGroup_Click()
Select Case Me![OptionGroup]
Case 1
Me.Textbox1.Visible = True
... = False
Case 2
Me.Textbox1.Visible = False
... = True
End Select
End Sub
This will make sure that if the user selects one option, then changes her mind, the proper text boxes are displayed.
You will also want to add this code to the On Current event of the form so that as a user scrolls through records, the proper text boxes are displayed, unless this is only an Add record form.
Did that help?
mmcdonal
|
|

September 28th, 2007, 09:56 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
Oh, Select is good for more than 2 options. If there are just two, you can use an If Then Else conditional.
mmcdonal
|
|

September 28th, 2007, 09:59 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
This book online: Beginning Access 2003 VBA is a good resource for these sorts of issues.
http://wrox.books24x7.com
mmcdonal
|
|

September 28th, 2007, 10:22 AM
|
|
Authorized User
|
|
Join Date: Sep 2007
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi mmcdonal,
That worked great. Thanku!
The text box that i'm making visible diplays a text (say option1 for case 1, option2 for case 2....) according to the option selected by user. Is it possible to display different text with different options in the same text box or do i need to use 6 different text boxes ?
The following didn't work -
Case 1
Me.Textbox1.Visible = True
Me.Textbox1.ControlSource = "option1"
... = False
Case 2
Me.Textbox1.Visible = True
Me.Textbox1.ControlSource = "option2"
Thanks
|
|

September 28th, 2007, 10:31 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
You can use the same text box and display different captions for labels like this:
Case 1
Me.Textbox1.Visible = True
Me.Label1.Caption = "option1"
... = False
Case 2
Me.Textbox2.Visible = True
Me.Label2.Caption = "option2"
The issue is, I guess these are unboun text boxes? I am assuming you want the user to enter something into the text box, and then you are going to take that entry and do something with it. If you have bound text boxes, then use individual ones to keep it clear. You CAN use one text box and either bind it with the selection, or chose where to send the data on some later event, but bound boxes involve the least amount of coding.
Did that help?
mmcdonal
|
|

September 28th, 2007, 11:39 AM
|
|
Authorized User
|
|
Join Date: Sep 2007
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Great. Thank you very much!
|
|
 |