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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional subform 1

Status
Not open for further replies.

twice300

Technical User
Jan 31, 2007
19
I've searched all forums and can't find anything similar, so sorry if this has been discussed before.

I have an employee table that has a Children yes/no field. On the employee form I have added a children subform as a datasheet.

I'd like to make the subform conditional, that is, if I check the Children? yes/no field, then I'd like to enable the subform, if the field (Children?) is unchecked, then I want the subform to be disabled.

Is this possible?

Thanks in advance for your help.
 
Yes, it is. You will need to add code to the Current event of the main form and the After Update event of the Children yes/no field, for example:
Code:
Private Sub Form_Current()
Me.Children_Subform.Enabled = Me.ChildrenYesNo
End Sub

Private Sub ChildrenYesNo_AfterUpdate()
Me.Children_Subform.Enabled = Me.ChildrenYesNo
End Sub
 
Remou,

thank you very much! worked like a charm...

have a nice day...
 
Remou,

Sorry to bother again. As I mentioned before, your suggestions worked perfectly. The children subform displays if I click on the Children field (yes/no) field on the main form.

I had the subform working, but I had the subform select the employee using a lookup to the Clerks table.

Since this is a subform, I'd like to have the EmployeeName in the subform set automatically to the Clerks.Name field from the main form. I've searched and read many articles but can't get it to work.

I read an article that mentioned that if I set the link master/child to the corresponding fields, this would work. I have set the fields Clerk.Name = Children.EmployeeName, but when I go into the subform, the Children.EmployeeName is not set automatically with the contents of the mainEmployeeName field, actually it reads frmClerks (this is the name of the main form).

Some background info for you.

Employee table fields:

Clerks Table has:
Name as text, here is where I store the employee name
Children as Yes/No

Children Table has:
ChildId as AutoNumber
EmployeeName as text
ChildName
ChildBirthDate

I have a one to many relationship for these two tables, tied by the Name - EmployeeName fields.


If I'm confusing sorry, I know this is long, but I'm stuck.

TIA
Twice300
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top