F
Fysh1
Ok I finally got it to work if any of you want the code
for your own use here it is. You will have to change it
to reflect for your own needs.
Private Sub cmdLink_Click()
On Error GoTo Err_cmdLink_Click
Dim vClinic As Variant
Dim vType As Variant
Dim ctl As Control
Dim varItm As Variant
Dim db As Database
Dim rst As Recordset
Set ctl = Me.TypeList
vClinic = Me.ClinicList
If Me.ClinicList < 1 Or Me.TypeList < 1 Then
MsgBox "Select a Clinic and Appointment Type to Link",
vbCritical, "SELECT A CLINIC AND APPOINTMENT TYPE"
Else
Set db = CurrentDb()
For Each varItm In ctl.ItemsSelected
Set rst = db.OpenRecordset("tblClinicType")
rst.Index = "PrimaryKey"
rst.Seek "=", vClinic, ctl.ItemData(varItm)
With rst
If .NoMatch Then
.AddNew
![ClinicID] = vClinic
![TypeID] = ctl.ItemData(varItm)
.Update
End If
End With
Next varItm
db.Close
Me.ClinictoList.Requery
End If
Exit_cmdLink_Click:
Exit Sub
Err_cmdLink_Click:
MsgBox Err.Description
Resume Exit_cmdLink_Click
End Sub
for your own use here it is. You will have to change it
to reflect for your own needs.
Private Sub cmdLink_Click()
On Error GoTo Err_cmdLink_Click
Dim vClinic As Variant
Dim vType As Variant
Dim ctl As Control
Dim varItm As Variant
Dim db As Database
Dim rst As Recordset
Set ctl = Me.TypeList
vClinic = Me.ClinicList
If Me.ClinicList < 1 Or Me.TypeList < 1 Then
MsgBox "Select a Clinic and Appointment Type to Link",
vbCritical, "SELECT A CLINIC AND APPOINTMENT TYPE"
Else
Set db = CurrentDb()
For Each varItm In ctl.ItemsSelected
Set rst = db.OpenRecordset("tblClinicType")
rst.Index = "PrimaryKey"
rst.Seek "=", vClinic, ctl.ItemData(varItm)
With rst
If .NoMatch Then
.AddNew
![ClinicID] = vClinic
![TypeID] = ctl.ItemData(varItm)
.Update
End If
End With
Next varItm
db.Close
Me.ClinictoList.Requery
End If
Exit_cmdLink_Click:
Exit Sub
Err_cmdLink_Click:
MsgBox Err.Description
Resume Exit_cmdLink_Click
End Sub