Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Howto change subforms depending on data entered into main form?

Status
Not open for further replies.

Soulbait

MIS
Mar 12, 2003
43
US
Is this possible?

I'm wondering if I could get it to automagically change forms when that data is changed in the main form.

For instance I have Main Form, then a field within main form we will call FormType with 4 different options (1,2,3,4)
Now if I enter 1 into the field I would like it to display subform1, enter 2, display subform2 and so on.

I'm fairly new to Access programming and this is just one of many questions I will be asking.

Thanks in advance.

 
Hi,


Past this in FormType's "After Update" event:

Select Case Me!FormType
Case 1
DoCmd.OpenForm "SubForm1"
Case 2
DoCmd.OpenForm "SubForm2"
Case 3
DoCmd.OpenForm "SubForm3"
Case 4
DoCmd.OpenForm "SubForm4"
End Select

HTH,

jbehrne
If at first you don't succeed, call in an airstrike. - Murphy's Laws of Combat Operations
 
That did not work, its still adding to just the original subform.

 
Sorry,

Try this instead:
Paste into your Form's "On Open" event:
Me!SubForm1.Visible = False
Me!SubForm2.Visible = False
Me!SubForm4.Visible = False
Me!SubForm4.Visible = False

paste into FormType's "After Update" Event
If Me!FormType = 1
Me!SubForm1.Visible = True
Me!SubForm2.Visible = False
Me!SubForm4.Visible = False
Me!SubForm4.Visible = False
ElseIf Me!FormType = 2
Me!SubForm1.Visible = False
Me!SubForm2.Visible = True
Me!SubForm4.Visible = False
Me!SubForm4.Visible = False
ElseIf Me!FormType = 3
Me!SubForm1.Visible = False
Me!SubForm2.Visible = False
Me!SubForm4.Visible = True
Me!SubForm4.Visible = False
ElseIf Me!FormType = 4
Me!SubForm1.Visible = False
Me!SubForm2.Visible = False
Me!SubForm4.Visible = False
Me!SubForm4.Visible = True
End If

jbehrne If at first you don't succeed, call in an airstrike. - Murphy's Laws of Combat Operations
 
Access seems to be thinking its looking for a field with that.

Each time I update the field a message pops up saying it can not find the field "Subform1"

I tried to make it be more specific by using [mainform]![subform1] along with a couple other different types
 
Hi,

You need to change SubForm1, SubForm2... to the names of your subforms on your main form. Don't put [mainform] in place of the Me...

HTH,

jbehrne If at first you don't succeed, call in an airstrike. - Murphy's Laws of Combat Operations
 
I did change the names, but in its current state with the ME!Card1

I am receiving a syntax error..
 
Hi,

Post your code and I'll take a look at it,

jbehrne If at first you don't succeed, call in an airstrike. - Murphy's Laws of Combat Operations
 
Private Sub Card_Enter()

Me!Card1.Visible = False
Me!Card2.Visible = False
Me!Card4.Visible = False
Me!Card4.Visible = False

End Sub

Private Sub Card_Type_AfterUpdate()

If Me![Card Type] = 1
Me!Card1.Visible = True
Me!Card2.Visible = False
Me!Card4.Visible = False
Me!Card4.Visible = False
ElseIf Me![Card Type] = 2
Me!Card1.Visible = False
Me!Card2.Visible = True
Me!Card4.Visible = False
Me!Card4.Visible = False
ElseIf Me![Card Type] = 3
Me!Card1.Visible = False
Me!Card2.Visible = False
Me!Card4.Visible = True
Me!Card4.Visible = False
ElseIf Me![Card Type] = 4
Me!Card1.Visible = False
Me!Card2.Visible = False
Me!Card4.Visible = False
Me!Card4.Visible = True
End If

End Sub
 
I've never liked the syntax for subforms. The Select statement works fine for me when I include the main form name(Form1):

Forms!Form1!Subform1.Visible = True
Forms!Form1!Subform2.Visible = False

Simon Rouse
 
Ok i tried that as well, still getting syntax error and when i click OK to that,

Private Sub Card_Type_AfterUpdate() <----This line is yellow

If Forms!Patients![Card Type] = 1 <----This line is highlighted
 
Hi Soulbait,

If you don't mind, you could send me a zipped copy (with all sensitive records removed). I would be happy to look at your db and find the cause. You can send it to me @ jbehrne@hotmail.com

Of course, if you don't want to I understand. I am still looking for the cause...

jbehrne If at first you don't succeed, call in an airstrike. - Murphy's Laws of Combat Operations
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top