Creating a Conditional Subform

steven.butler

Registered User.
Local time
Today, 04:30
Joined
Jul 19, 2007
Messages
12
Hello, I want to make a form with a conditional subform so that when selecting a specific value in one field, a specific subform appears.

I understand that it needs to go in the 'AfterUpdate' section of the field properties but I am struggling with coding it.

On the main form I have a Combo Box called 'Body System' (from the table '_Study') which can either be 'CV', 'PUL', 'Clinical' or 'CNS'.

When it is 'CV' I want to add the the subform 'Results CV'
When it is 'PUL' - the subform 'Results Pul'
When it is 'CNS' - the subform 'Results CNS'
When it is 'Clinical' - the subform 'Results Clinical'

I would be very grateful if somebody could help me with the coding that I need to be able to do this!

Thanks very much in advance for any help!

Steve
 
you need to change the sub forms Source object property
Code:
SELECT CASE [Body System]
           CASE "CV"
           Forms!myMainForm!SubformContainerName.SourceObject="Results CV"
           CASE "Pul
           Forms!myMainForm!SubformContainerName.SourceObject="Results Pul"
END SELECT

you may require to use this form instead

Forms!myMainForm!SubformContainerName.Form.SourceObject="Results CV"
 
Sorry for the double post.

I have tried the code but it is not working.

Can the subform come from a form or does it have to come from a table?

Is there anyway of doing it by using the Macro Builder or the Expression Builder?

Does the fact that it is a Combo Box make any difference to the coding used?

Cheers
 
I am now getting the reply:

'could not find 'myMainForm''

I have subsequently changed it to 'my_StudyForm' (because my form is called '_Study' but I have still not had any luck!

Thanks again
 
Forms!myMainForm!SubformContainerName

myMainForm = _Study
SubformContainerName = Whatever you've called your subform

Replace these and all should be well.
 
Cheers Matt,

I have now solved the myMainForm name

But get the error message about my subforms.

At the moment I have got 4 other forms that contain the specific information that I want to come into my subform. Can I do it from this? Or do I need to actually create other subforms first?

Thanks, Steve
 
Steven,
a form only becomes a sub form when it is embedded in another form.
What is the error message?
 
Just to clarify a point. Except for unbound controls, forms don't contain data, they display it. So the concept of gathering datafrom other forms is not right. The data would normally come from a query, though you can go direct to the table.
 
it is:

runtime error '2465:'

Can't find the field ResultsCNS referred to in your expression.

Ok so what if I want selecting those specific options to add on another part of the form on the side??

Thanks again
 
neileg:

I appreciate that forms are to display data.

The first half of my form is standard and applies to all data input but the 2nd half depends on what option is selected from a combo box from the first half.

I want the second half of the form to therefore to 'appear' upon selecting the option from the combo box.

Would it be possible to do this by using a tab control box?
Because one entry in the first half of the form can lead to 5 entries in the second half of the form?
Any help on how I could to this would be greatly appreciated!

Thanks, Steve
 
why not make all the subforms invisible? when you need a form, you'd make it visible...
lets say when your CV selected in the combo, the form would appear. Put the code in AfterUpdate event
If cboName = "CV" Then
subfrmCV.Form.Visible = True
End If
 

Users who are viewing this thread

Back
Top Bottom