Go Back   Access World Forums > Microsoft Access Discussion > Forms

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 07-24-2013, 02:22 AM   #1
KateM
Newly Registered User
 
Join Date: Jul 2013
Location: Oxford, UK
Posts: 23
Thanks: 2
Thanked 0 Times in 0 Posts
KateM is on a distinguished road
Problem with subforms - visible / invisible

Hi All

As a newbie, I have what might be a beginners problem

I have created a form to interrogate our database and display all records without a unique building reference code OSAPR. The form has two subforms which hold details of domestic and occupational addresses and OSAPR codes. Only one subform should be displayed at any one time.

The idea is that when a new record number (primary key called holding_id) is on the form, a bit of code runs which looks at the txttype to determine whether it is a D (domestic address) or O (occupational address).

The two subforms are set as visible = no, so they only become visible under the above circumstances.

I then have a matched and an unmatched button to update the table behind the form.

I have tried various codes to sort out the two subforms, currently I have:

Private Sub txtHolding_id_GotFocus()
If Me.txtType = D Then
Me.dbo_OSAddress_subformD.Visible = True
Exit Sub
If Me.txtType = O Then
Me.dbo_OSAddress_subformO.Visible = True
Exit Sub
End If
End Sub

however not only is the domestic subform visible at all times, regardless of the txttype code being D or O, but I also get an error message :

"Compile error: Method or data member not found"

Please advise - what am I doing wrong?

Thanks, Kate

KateM is offline   Reply With Quote
Old 07-24-2013, 04:02 AM   #2
CJ_London
Super Moderator
 
Join Date: Feb 2013
Location: UK
Posts: 10,179
Thanks: 39
Thanked 3,292 Times in 3,188 Posts
CJ_London is just really nice CJ_London is just really nice CJ_London is just really nice CJ_London is just really nice CJ_London is just really nice
Re: Problem with subforms - visible / invisible

You need to surrount the D and O with double quotes i.e.
= "D"

Better coding would be

Code:
 
Me.dbo_OSAddress_subformD.Visible = Me.txtType = "D" Me.dbo_OSAddress_subformO.Visible = Me.txtType = "O"
However since both are addresses, I'm not sure why you need to have two different subforms to display what is presumbly the same form of data (Addr1,2,3..)
__________________
CJ_London
_______________________
A little thanks goes a long way. If you have found this post useful, please tick the thanks button
CJ_London is offline   Reply With Quote
Old 07-24-2013, 05:03 AM   #3
KateM
Newly Registered User
 
Join Date: Jul 2013
Location: Oxford, UK
Posts: 23
Thanks: 2
Thanked 0 Times in 0 Posts
KateM is on a distinguished road
Re: Problem with subforms - visible / invisible

Hi CJ_London

Thanks for your reply.

I've changed it as you suggested, but I'm still getting the same error message - Compile Error Method or data member not found.

It doesn't seem to like the .txtType - which it highlights in blue. It also highlights the Private Sub txtholding_id_GotFocus () section in yellow...

I have made the two forms because the workplace addresses have extra columns at the start which are not relevant to the domestic addresses and I'm trying to avoid having to scroll across the subform when doing the manual matching of addresses.

Do you have any further suggestions, please?

Regards

Kate

KateM is offline   Reply With Quote
Old 07-24-2013, 05:08 AM   #4
Lenford
Newly Registered User
 
Join Date: Dec 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Lenford is on a distinguished road
Re: Problem with subforms - visible / invisible

Perhaps try:

If Me.txtType = "D" Then
Me.dbo_OSAddress_subformD.Visible = True
Me.dbo_OSAddress_subformO.Visible = False
Else If Me.txtType = "O" Then
Me.dbo_OSAddress_subformO.Visible = True
Me.dbo_OSAddress_subformD.Visible = False
End If
Lenford is offline   Reply With Quote
Old 07-24-2013, 05:18 AM   #5
KateM
Newly Registered User
 
Join Date: Jul 2013
Location: Oxford, UK
Posts: 23
Thanks: 2
Thanked 0 Times in 0 Posts
KateM is on a distinguished road
Re: Problem with subforms - visible / invisible

Hi Lenford

I've tried your suggestion but the Else statement is in red.

If I change it to have an Exit sub after the "D" section then I'm still getting the same compile error and the .dbo_OSAddress_subformD or .dbo_OSAddress_subformO is highlighted in blue....

Regards

Kate

Last edited by KateM; 07-24-2013 at 05:27 AM.
KateM is offline   Reply With Quote
Old 07-24-2013, 05:53 AM   #6
CJ_London
Super Moderator
 
Join Date: Feb 2013
Location: UK
Posts: 10,179
Thanks: 39
Thanked 3,292 Times in 3,188 Posts
CJ_London is just really nice CJ_London is just really nice CJ_London is just really nice CJ_London is just really nice CJ_London is just really nice
Re: Problem with subforms - visible / invisible

I think the problem is with your control txtType - is the control source Type?
__________________
CJ_London
_______________________
A little thanks goes a long way. If you have found this post useful, please tick the thanks button
CJ_London is offline   Reply With Quote
Old 07-24-2013, 06:25 AM   #7
Mihail
Newly Registered User
 
Join Date: Jan 2011
Location: Romania
Posts: 2,373
Thanks: 90
Thanked 367 Times in 362 Posts
Mihail is on a distinguished road
Re: Problem with subforms - visible / invisible

Check again the names. Seems that you have typing something wrong.
One more point about CJ (air) code (that you should use):
Me.dbo_OSAddress_subformD.Visible = (Me.txtType = "D")
Me.dbo_OSAddress_subformO.Visible = (Me.txtType = "O")

Mihail is offline   Reply With Quote
Old 07-24-2013, 06:42 AM   #8
KateM
Newly Registered User
 
Join Date: Jul 2013
Location: Oxford, UK
Posts: 23
Thanks: 2
Thanked 0 Times in 0 Posts
KateM is on a distinguished road
Re: Problem with subforms - visible / invisible

CJ_London - the control source is Type - which is on the underlying table. I just called the text box txtType, as that seems to be the correct protocol. Is that incorrect?


Mihail - thanks, but when I tried your suggestion, having commented out the others, I still get the same compile error, but the .txtType is highlighted in blue.

I assume that there is something wrong with the two sub-forms, so I'll just have to keep trying various options !

Regards

Kate
KateM is offline   Reply With Quote
Old 07-24-2013, 06:58 AM   #9
CJ_London
Super Moderator
 
Join Date: Feb 2013
Location: UK
Posts: 10,179
Thanks: 39
Thanked 3,292 Times in 3,188 Posts
CJ_London is just really nice CJ_London is just really nice CJ_London is just really nice CJ_London is just really nice CJ_London is just really nice
Re: Problem with subforms - visible / invisible

Quote:
the control source is Type
This is almost certainly where your problem lies - Type is a reserved word and can produce unexpected results - suggest you change it to something else and see if this solves the problem

This link gives you a list of Access reserved words

http://support.microsoft.com/kb/286335
__________________
CJ_London
_______________________
A little thanks goes a long way. If you have found this post useful, please tick the thanks button
CJ_London is offline   Reply With Quote
Old 07-24-2013, 07:59 AM   #10
Mihail
Newly Registered User
 
Join Date: Jan 2011
Location: Romania
Posts: 2,373
Thanks: 90
Thanked 367 Times in 362 Posts
Mihail is on a distinguished road
Re: Problem with subforms - visible / invisible

Are you sure (very sure) that your control is named txtType?????

@CJ_London
This time I don't agree with you because I never seen the "Type" name. I see txtType.
Is something that I missing ?
Mihail is offline   Reply With Quote
Old 07-24-2013, 08:04 AM   #11
CJ_London
Super Moderator
 
Join Date: Feb 2013
Location: UK
Posts: 10,179
Thanks: 39
Thanked 3,292 Times in 3,188 Posts
CJ_London is just really nice CJ_London is just really nice CJ_London is just really nice CJ_London is just really nice CJ_London is just really nice
Re: Problem with subforms - visible / invisible

@Mihail

I quote the OP

Quote:
the control source is Type - which is on the underlying table
__________________
CJ_London
_______________________
A little thanks goes a long way. If you have found this post useful, please tick the thanks button
CJ_London is offline   Reply With Quote
Old 07-24-2013, 08:38 AM   #12
Mihail
Newly Registered User
 
Join Date: Jan 2011
Location: Romania
Posts: 2,373
Thanks: 90
Thanked 367 Times in 362 Posts
Mihail is on a distinguished road
Re: Problem with subforms - visible / invisible

Now I see. Post 8. Old age...
Mihail is offline   Reply With Quote
Old 07-26-2013, 07:04 AM   #13
KateM
Newly Registered User
 
Join Date: Jul 2013
Location: Oxford, UK
Posts: 23
Thanks: 2
Thanked 0 Times in 0 Posts
KateM is on a distinguished road
Re: Problem with subforms - visible / invisible

Thanks for all of your suggestions. I ended up deleting that form and starting again with a single subform and narrower columns to reduce scrolling.....!

Perhaps when I've developed some knowledge in a few months I'll try again with the two subforms...

Kate

KateM is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
visible and invisible logic joe789 Forms 3 07-03-2012 11:42 AM
Subforms visible/invisible based on option group selection vangogh228 Forms 1 09-21-2007 08:33 AM
Problem with visible/ invisible text in page header rbrule Reports 2 04-19-2004 01:09 AM
Visible/Invisible goaksmith Macros 3 10-25-2002 06:22 AM
Visible or Invisible andy101 Forms 1 03-10-2001 08:02 PM




All times are GMT -8. The time now is 07:18 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Sponsored Links

How to advertise

Media Kit


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World