Hello all,
I have a table "tblContact s" that holds my Contact Info. Because there can be multiple Contact Types for a Contact, I have a second table "tlnkContactTyp es" in which there is a record for every Contact / Type combination.
tblContacts: ContactID, NmFirst, NmLast. etc...
tlnkContactType s: ContactID, ContactType (which is selected from value list)
For a summary query I need to Show all of the Contact Types for a contact together. I have found a public function called "Conc" (see below) that does a nice job of concatenating all Contact Types for a ContactID from tlnkContactType s into one field.
So tlnkContactType s
ContactID ContactType
1 Resident
1 Super
2 Resident
2 Teacher
3 Teacher
is transformed to qryContactTypes Cnct
ContactID ContactTypes
1 Resident, Super
2 Resident, Teacher
3 Teacher
The problem that I have is that not all Contacts are represented in tlnkContactType s, because a Contact may not have a Type. When I create my summary query based on tblContacts and include qryContactTypes Cnct, I get an error message for every record in tblContacts that is not represented in qryContactTypes Cnct.
I cannot figure out how to make it enter a "blank" value for Contacts that are not in qryContactTypes Cnct. Any advice would be appreciated!
Banderson
For my project, the variables in the function below are define as follows:
Fieldx = ContactType",
Identity = "ContactID" ,
Value = [ContactID],
Source = "tlnkContactTyp es"
I use the public function below in my qryContactTypes Cnct SQL like this:
SELECT tlnkContactType s.ContactID, Conc("ContactTy pe","ContactID" ,[ContactID],"tlnkContactTy pes") AS ContactTypes
FROM tlnkContactType s
GROUP BY tlnkContactType s.ContactID;
[code=vb]
Public Function Conc(Fieldx, Identity, Value, Source) As Variant
Dim cnn As ADODB.Connectio n
Dim Rs As ADODB.Recordset
Dim SQL As String
Dim vFld As Variant
Set cnn = CurrentProject. Connection
Set Rs = New ADODB.Recordset
vFld = Null
SQL = "SELECT [" & Fieldx & "] as Fld" & _
" FROM [" & Source & "]" & _
" WHERE [" & Identity & "]=" & Value
' open recordset.
Rs.Open SQL, cnn, adOpenForwardOn ly, adLockReadOnly
' concatenate the field.
Do While Not Rs.EOF
If Not IsNull(Rs!Fld) Then
vFld = vFld & ", " & Rs!Fld
End If
Rs.MoveNext
Loop
' remove leading comma and space.
vFld = Mid(vFld, 3)
Set cnn = Nothing
Set Rs = Nothing
' return concatenated string.
Conc = vFld
End Function
[/code]
I have a table "tblContact s" that holds my Contact Info. Because there can be multiple Contact Types for a Contact, I have a second table "tlnkContactTyp es" in which there is a record for every Contact / Type combination.
tblContacts: ContactID, NmFirst, NmLast. etc...
tlnkContactType s: ContactID, ContactType (which is selected from value list)
For a summary query I need to Show all of the Contact Types for a contact together. I have found a public function called "Conc" (see below) that does a nice job of concatenating all Contact Types for a ContactID from tlnkContactType s into one field.
So tlnkContactType s
ContactID ContactType
1 Resident
1 Super
2 Resident
2 Teacher
3 Teacher
is transformed to qryContactTypes Cnct
ContactID ContactTypes
1 Resident, Super
2 Resident, Teacher
3 Teacher
The problem that I have is that not all Contacts are represented in tlnkContactType s, because a Contact may not have a Type. When I create my summary query based on tblContacts and include qryContactTypes Cnct, I get an error message for every record in tblContacts that is not represented in qryContactTypes Cnct.
I cannot figure out how to make it enter a "blank" value for Contacts that are not in qryContactTypes Cnct. Any advice would be appreciated!
Banderson
For my project, the variables in the function below are define as follows:
Fieldx = ContactType",
Identity = "ContactID" ,
Value = [ContactID],
Source = "tlnkContactTyp es"
I use the public function below in my qryContactTypes Cnct SQL like this:
SELECT tlnkContactType s.ContactID, Conc("ContactTy pe","ContactID" ,[ContactID],"tlnkContactTy pes") AS ContactTypes
FROM tlnkContactType s
GROUP BY tlnkContactType s.ContactID;
[code=vb]
Public Function Conc(Fieldx, Identity, Value, Source) As Variant
Dim cnn As ADODB.Connectio n
Dim Rs As ADODB.Recordset
Dim SQL As String
Dim vFld As Variant
Set cnn = CurrentProject. Connection
Set Rs = New ADODB.Recordset
vFld = Null
SQL = "SELECT [" & Fieldx & "] as Fld" & _
" FROM [" & Source & "]" & _
" WHERE [" & Identity & "]=" & Value
' open recordset.
Rs.Open SQL, cnn, adOpenForwardOn ly, adLockReadOnly
' concatenate the field.
Do While Not Rs.EOF
If Not IsNull(Rs!Fld) Then
vFld = vFld & ", " & Rs!Fld
End If
Rs.MoveNext
Loop
' remove leading comma and space.
vFld = Mid(vFld, 3)
Set cnn = Nothing
Set Rs = Nothing
' return concatenated string.
Conc = vFld
End Function
[/code]
Comment