My combo box on my form will not accept any new data,and wont update the table, I have two tables with the same field and they are liked.What am I doing wrong?
Put Limit To List = Yes and write codes like following in procedure NotInList:
Private Sub cboMyComboBox_NotInList(NewData As String, Response As Integer)
Response = acDataErrContinue
Me.cboMyComboBox.Undo
If MsgBox("Do you want to add a new record?", vbYesNo + vbQuestion + vbDefaultButton2, "New data" = vbYes Then
DoCmd.GoToRecord , , acNewRec
Me.cboMyComboBox = NewData
End If
End Sub
If your Sorce data of combobox have primary key it's needed that you check for duplicate data in the table:
Private Sub cboMyComboBox_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_cboMyComboBox_BeforeUpdate
Dim lngSearh As Long
If Me.cboMyComboBox = Me.cboMyComboBox.OldValue Then
GoTo Exit_cboMyComboBox_BeforeUpdate
End If
Set rst = Me.RecordsetClone
rst.FindFirst "ID=" & Me.cboMyComboBox
If Not rst.NoMatch Then
MsgBox "Duplicate values!"
Me.cboMyComboBox.Undo
Cancel = True
End If
rst.Close
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.