Hi everyone
I have a question about DLookup and wether or not it should be used in this case. I have a pretty complex table structure in the db so for this sake of this example lets just say I have a db with 3 tables: 1 Parent table and 2 children tables - one child with many to one relationship and the other with a one to one relationship. I'm trying to check 2 variables to see if they meet a certain requirement. Here is the present code (slimmed down for the example)
Dim HCP As String
Dim HCT As Boolean
HCP = Nz(DLookup("[HC_plate]", "BAS_SkidPier", "SITEID='" & [Forms]![frmMain]![SITEID].[Value] & "'"))
HCT = Nz(DLookup("[HC_Toilet]", "BAS_toilet", "SITEID='" & [Forms]![frmMain]![SITEID].[Value] & "'"))
If IsNull(HCP) Or HCP = "" Then
Exit Sub
Else
Me.txtHC_plate.Value = HCP
End If
If IsNull(HCT) Then
Exit Sub
Else
Me.txtHC_Toilet.Value = HCT
End If
At this time I have put two unbound fields (txtHC_plate and txtHC_Toilet) on the form just to see if I am capturing the correct data for the current record on the form (frmMain).
Now - the problem: The DLookup function always works with the one to one table as there is only one record BUT for the table with the one to many join it finds only the first record and then uses that for the value. How can I set this up to look at all of the related values on the many side? Do I need a loop?
Any and all help on this is appreciated.
Thanks -Kevin
I have a question about DLookup and wether or not it should be used in this case. I have a pretty complex table structure in the db so for this sake of this example lets just say I have a db with 3 tables: 1 Parent table and 2 children tables - one child with many to one relationship and the other with a one to one relationship. I'm trying to check 2 variables to see if they meet a certain requirement. Here is the present code (slimmed down for the example)
Dim HCP As String
Dim HCT As Boolean
HCP = Nz(DLookup("[HC_plate]", "BAS_SkidPier", "SITEID='" & [Forms]![frmMain]![SITEID].[Value] & "'"))
HCT = Nz(DLookup("[HC_Toilet]", "BAS_toilet", "SITEID='" & [Forms]![frmMain]![SITEID].[Value] & "'"))
If IsNull(HCP) Or HCP = "" Then
Exit Sub
Else
Me.txtHC_plate.Value = HCP
End If
If IsNull(HCT) Then
Exit Sub
Else
Me.txtHC_Toilet.Value = HCT
End If
At this time I have put two unbound fields (txtHC_plate and txtHC_Toilet) on the form just to see if I am capturing the correct data for the current record on the form (frmMain).
Now - the problem: The DLookup function always works with the one to one table as there is only one record BUT for the table with the one to many join it finds only the first record and then uses that for the value. How can I set this up to look at all of the related values on the many side? Do I need a loop?
Any and all help on this is appreciated.
Thanks -Kevin