Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Entering New Data

Status
Not open for further replies.

Demon36

Technical User
Jun 9, 2001
7
US
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?
 
Check the LimitToList property of the combo box. It should be set to No
 
That didnt work, I must have something else wrong
 
Hi again!

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

Exit_cboMyComboBox_BeforeUpdate:
Exit Sub

Err_cboMyComboBox_BeforeUpdate:
MsgBox Err.Number & vbLf & Err.Description
Resume Exit_cboMyComboBox_BeforeUpdate

End Sub

Aivars
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top