Hi,
I successfully use the code below in Access XP at home, but when I try at work in Access 97, nothing happens. I need the user to be prompted to add the value to the table if it is not in the combo box. Any suggestions? Here's the code:
Private Sub cboAcct_NotInList(NewData As String, Response As Integer)
Dim dbs As DAO.Database
Dim rs As DAO.Recordset
If vbNo = MsgBox("The 'Master Customer Number' specified is not in the list." & vbCr & vbCr & "Do you want to add it now?", vbQuestion + vbYesNo + vbDefaultButton2, "basNotInList") Then
Response = acDataErrContinue
End If
Set db = CurrentDb
Set rs = db.OpenRecordset("Accounts", dbOpenDynaset)
rs.AddNew
rs.Fields(0) = (cboAcct.ListCount + 2)
rs.Fields(1) = NewData
rs.Update
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
Response = acDataErrAdded
End Sub
Thanks,
Chris
I successfully use the code below in Access XP at home, but when I try at work in Access 97, nothing happens. I need the user to be prompted to add the value to the table if it is not in the combo box. Any suggestions? Here's the code:
Private Sub cboAcct_NotInList(NewData As String, Response As Integer)
Dim dbs As DAO.Database
Dim rs As DAO.Recordset
If vbNo = MsgBox("The 'Master Customer Number' specified is not in the list." & vbCr & vbCr & "Do you want to add it now?", vbQuestion + vbYesNo + vbDefaultButton2, "basNotInList") Then
Response = acDataErrContinue
End If
Set db = CurrentDb
Set rs = db.OpenRecordset("Accounts", dbOpenDynaset)
rs.AddNew
rs.Fields(0) = (cboAcct.ListCount + 2)
rs.Fields(1) = NewData
rs.Update
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
Response = acDataErrAdded
End Sub
Thanks,
Chris