So I have this checkbox on a form, when its checked it's supposed to add a record to a table. When it's unchecked it deletes the corresponding record. I am working with Access 2003 on a WinXP pro box. I can get the connection open, but it says it can't find the refrenced table. It's there, but I might have messed up the connection. This is what i have so far:
Private Sub chkVet_Click()
Dim strsql As String
Dim con As Connection
Dim ID As String
ID = (Me!EmployeeID)
Set con = New ADODB.Connection
con.CursorLocation = adUseClient
con.Open "Provider=MSDAOSP; Data Source=MSXML2.DSOControl.2.6;"
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
strsql = "SELECT * FROM Employee_Vet"
rs.CursorLocation = adUseClient
rs.Open strsql, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
If chkVet.Value = True Then
rs.AddNew "EmployeeID", ID
rs.Update
strsql = "UPDATE Employee_Vet SET Employee_Vet.Vet_Class = 'Veteran' WHERE Employee_Vet.EmployeeID = '" & ID & "'"
Else
strsql = "DELETE FROM Employee_Vet WHERE Employee_Vet.EmployeeID = '" & (Me!EmployeeID) & "' AND Employee_Vet.Vet_Class = 'Veteran'"
End If
con.Execute (strsql)
rs.Close
con.Close
End Sub
Private Sub chkVet_Click()
Dim strsql As String
Dim con As Connection
Dim ID As String
ID = (Me!EmployeeID)
Set con = New ADODB.Connection
con.CursorLocation = adUseClient
con.Open "Provider=MSDAOSP; Data Source=MSXML2.DSOControl.2.6;"
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
strsql = "SELECT * FROM Employee_Vet"
rs.CursorLocation = adUseClient
rs.Open strsql, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
If chkVet.Value = True Then
rs.AddNew "EmployeeID", ID
rs.Update
strsql = "UPDATE Employee_Vet SET Employee_Vet.Vet_Class = 'Veteran' WHERE Employee_Vet.EmployeeID = '" & ID & "'"
Else
strsql = "DELETE FROM Employee_Vet WHERE Employee_Vet.EmployeeID = '" & (Me!EmployeeID) & "' AND Employee_Vet.Vet_Class = 'Veteran'"
End If
con.Execute (strsql)
rs.Close
con.Close
End Sub