Dim db As Database
Dim tdf As TableDef
Dim fld As Field
Dim rst As Recordset
Dim strSQL As String
Dim strTableName As String
' 1: Create a new temporary table containing the required fields
strSQL = "SELECT Patient_Beademingsmachine.PatientId, Patient_Beademingsmachine.BeademingsmachineId " & _
"INTO tblTemp " & _
"FROM Patient_Beademingsmachine " & _
"WHERE Patient_Beademingsmachine.PatientId = " & backofficenummer & ";"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
'2: Selecteren van de tabel
Set db = CurrentDb()
Set tdf = db.TableDefs("tblTemp")
'3: Lezen van de inhoud
On Error Resume Next
Set rst = db.OpenRecordset("tblTemp", dbOpenTable)
rst.MoveFirst
Machines = ""
Do
ID = rst![BeademingsmachineId]
machine = DLookup("Beademingsmachine", "Beademingsmachines", "ID = " & ID)
If Machines = "" Then
Machines = machine
Else
Machines = Machines & ", " & machine
End If
rst.MoveNext
Loop Until rst.EOF
'4: Toekennen van de inhoud
Machines.Value = Machines
' 5: Delete the temporary table
db.TableDefs.Delete ("tblTemp")