Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old September 28th, 2007, 09:44 AM
Authorized User
 
Join Date: Sep 2007
Location: , , USA.
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.

  #2 (permalink)  
Old September 28th, 2007, 09:55 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

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
  #3 (permalink)  
Old September 28th, 2007, 09:56 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Oh, Select is good for more than 2 options. If there are just two, you can use an If Then Else conditional.

mmcdonal
  #4 (permalink)  
Old September 28th, 2007, 09:59 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

This book online: Beginning Access 2003 VBA is a good resource for these sorts of issues.

http://wrox.books24x7.com

mmcdonal
  #5 (permalink)  
Old September 28th, 2007, 10:22 AM
Authorized User
 
Join Date: Sep 2007
Location: , , USA.
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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


  #6 (permalink)  
Old September 28th, 2007, 10:31 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

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
  #7 (permalink)  
Old September 28th, 2007, 11:39 AM
Authorized User
 
Join Date: Sep 2007
Location: , , USA.
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Great. Thank you very much!


Similar Threads
Thread Thread Starter Forum Replies Last Post
Composite Control Property Exposure Invalid... alandye BOOK: Professional ASP.NET 2.0 Server Control and Component Development ISBN: 978-0-471-79350-2 3 March 23rd, 2007 02:43 PM
invalid reference NeoCat Access 4 September 20th, 2005 12:04 PM
Invalid use of property error. Bob Rupp BOOK: Beginning Access 2003 VBA 1 March 4th, 2005 09:09 AM
Invalid use of property hanna VB.NET 2002/2003 Basics 1 March 31st, 2004 06:31 PM
Invalid Use of Property Compile Error dubs70 Access VBA 8 March 9th, 2004 03:19 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.