I have a form with a combo box (CompNameSelect) whose control source is Table tblCompany. I want to take a selection from the combo box, test if a record exists in Table tbleToDo for the selection, if not make one, then make the selection the current record for the form. I'm using the following code but getting an error regarding duplicate records. Any help is appreciated.
Dim cmdSQL As String
Dim rs As Recordset
Set db = CurrentDb
cmdSQL = "select * from tblToDo where NameofComp='" + CompNameSelect + "'"
'cmdSQL = "select * from tblToDo where NameofComp='" + InputValue + "'"
Set rs = db.OpenRecordset(cmdSQL, dbOpenDynaset)
If rs.BOF And rs.EOF Then
With rs
.AddNew
!NameOfComp = CompNameSelect
.Update
End With
Else
Me.Bookmark = rs.Bookmark
End If
rs.Close
Me.CompNameSelect.Requery
Dim cmdSQL As String
Dim rs As Recordset
Set db = CurrentDb
cmdSQL = "select * from tblToDo where NameofComp='" + CompNameSelect + "'"
'cmdSQL = "select * from tblToDo where NameofComp='" + InputValue + "'"
Set rs = db.OpenRecordset(cmdSQL, dbOpenDynaset)
If rs.BOF And rs.EOF Then
With rs
.AddNew
!NameOfComp = CompNameSelect
.Update
End With
Else
Me.Bookmark = rs.Bookmark
End If
rs.Close
Me.CompNameSelect.Requery