G
Guest
In the code below, there is a statement Me.cboSkill.Requery. On this statement, I am getting an error message that says, "Run-time error '2118': You must save the current field before running the Requery action." I thought I had this working just a short while ago. Originally, the statement Me.cboSkills.Requery was missing and the prior statement was Response = acDataErrAdded. The problem with this was that records got written to the table twice.
How can the code be modified to successfully add a record to a table?
Thanks.
Anita
Private Sub cboSkills_NotInList(NewData As String, Response As Integer)
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Set cnn = CurrentProject.Connection
Set rst = New ADODB.Recordset
rst.Open Source:="tblSkills", ActiveConnection:=cnn, _
CursorType:=adOpenKeyset, LockType:=adLockPessimistic
If Me.txtContactID > 0 Then
With rst
.AddNew
!ContactID = Me.txtContactID
!Skills = NewData
.Update
End With
Response = acDataErrContinue
Me.cboSkills.Requery
Else
Response = acDataErrContinue
MsgBox "Skill was not added to list."
End If
rst.Close
Set rst = Nothing
End Sub
How can the code be modified to successfully add a record to a table?
Thanks.
Anita
Private Sub cboSkills_NotInList(NewData As String, Response As Integer)
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Set cnn = CurrentProject.Connection
Set rst = New ADODB.Recordset
rst.Open Source:="tblSkills", ActiveConnection:=cnn, _
CursorType:=adOpenKeyset, LockType:=adLockPessimistic
If Me.txtContactID > 0 Then
With rst
.AddNew
!ContactID = Me.txtContactID
!Skills = NewData
.Update
End With
Response = acDataErrContinue
Me.cboSkills.Requery
Else
Response = acDataErrContinue
MsgBox "Skill was not added to list."
End If
rst.Close
Set rst = Nothing
End Sub