I recently found this sample code on how to concatenate data fields:
Here: http://www.blueclaw-db.com/concatenate_multiple_records_one_field.htm
This is just what I need for my own tables. However, I don't know how to 'call' it. I can make the needed changes to use my table/field names, but how do I envoke/call/start it?
I'm sorry for such a basic question but any tips would be great.
Code:
Public Function concat_alrgy(Patient_ID)
Dim rst As DAO.Recordset
Dim db As DAO.Database
Dim hold_alrgy As String
Set db = CurrentDb
hold_alrgy = ""
[COLOR=#008000]' clear out old list
[/COLOR]
DoCmd.RunSQL ("delete * from t_patient_alrgy")
[COLOR=#008000]' start creating new list
' select list of records for this patient
[/COLOR]
Set rst = db.OpenRecordset("SELECT Allergy " & _
" FROM L_alrgy INNER JOIN M_Patient_alrgy " & _
" ON L_alrgy.Allergy_ID = M_Patient_alrgy.Allergy_ID " & _
" WHERE Patient_ID=" & Patient_ID)
[COLOR=#008000]' skip process if there are no items in the list[/COLOR]
If rst.BOF Or rst.EOF = True Then GoTo jump_out
rst.MoveFirst
[COLOR=#008000] ' start Concatenate Multiple Records to Text Field[/COLOR]
Do While Not rst.EOF
If hold_alrgy = "" Then
hold_alrgy = rst!Allergy
Else
hold_alrgy = hold_alrgy & "; " & rst!Allergy
End If
rst.MoveNext
Loop
[COLOR=#008000]' end Concatenate Multiple Records to Text Field[/COLOR]
jump_out:
rst.Close
Set rst = Nothing
[COLOR=#008000]' load the concatenated list[/COLOR]
DoCmd.RunSQL ("INSERT INTO T_Patient_alrgy ( Patient_ID, Allergy ) " & _
" SELECT " & Patient_ID & ",'" & hold_alrgy & "'")
End Function
This is just what I need for my own tables. However, I don't know how to 'call' it. I can make the needed changes to use my table/field names, but how do I envoke/call/start it?
I'm sorry for such a basic question but any tips would be great.