Problem with subforms - visible / invisible (1 Viewer)

KateM

Registered User.
Local time
Today, 14:32
Joined
Jul 24, 2013
Messages
23
Hi All

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

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
 

CJ_London

Super Moderator
Staff member
Local time
Today, 14:32
Joined
Feb 19, 2013
Messages
16,555
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..)
 

KateM

Registered User.
Local time
Today, 14:32
Joined
Jul 24, 2013
Messages
23
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
 

Lenford

New member
Local time
Today, 10:32
Joined
Dec 26, 2012
Messages
2
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
 

KateM

Registered User.
Local time
Today, 14:32
Joined
Jul 24, 2013
Messages
23
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:

CJ_London

Super Moderator
Staff member
Local time
Today, 14:32
Joined
Feb 19, 2013
Messages
16,555
I think the problem is with your control txtType - is the control source Type?
 

Mihail

Registered User.
Local time
Today, 16:32
Joined
Jan 22, 2011
Messages
2,373
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")
 

KateM

Registered User.
Local time
Today, 14:32
Joined
Jul 24, 2013
Messages
23
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
 

CJ_London

Super Moderator
Staff member
Local time
Today, 14:32
Joined
Feb 19, 2013
Messages
16,555
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
 

Mihail

Registered User.
Local time
Today, 16:32
Joined
Jan 22, 2011
Messages
2,373
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 ?
 

KateM

Registered User.
Local time
Today, 14:32
Joined
Jul 24, 2013
Messages
23
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
 

Users who are viewing this thread

Top Bottom