Code:
Sub cmbDiv_NotInList(NewData As String, Response As Integer)
Dim DB As Database
Dim RS As Recordset
Dim Msg As String
Dim CR As String: CR = Chr$(13)
' Exit Sub if the user cleared the selection.
If NewData = "" Then Exit Sub
' Ask if the user wants to add the new customer.
Msg = "'" & NewData & "' is not in the list." & CR & CR
Msg = Msg & "Do you want to add it?"
If MsgBox(Msg, 32 + 4) = 7 Then
' If the user chooses No, instruct the user to try again.
Response = DATA_ERRCONTINUE
MsgBox "Please try again."
Else
' If the user does not choose No, create a new record in the
' Customer table.
On Error Resume Next
' Open the Customer table.
Set DB = DBEngine.Workspaces(0).Databases(0)
Set RS = DB.OpenRecordset("Division", DB_OPEN_DYNASET)
RS.AddNew
RS![DivisionName] = NewData
RS.Update
' If an error occurred while adding the record...
If Err Then
' ...instruct the user to try again.
Response = DATA_ERRCONTINUE
Beep: MsgBox Error$, 48
MsgBox "Please try again."
Else
' If no error occurred, add the element to the combo box
' list.
Response = DATA_ERRADDED
End If
End If
End Sub
When i enter the data and press enter, it goes to debug and selects "Dim DB as Database"
Am i using old code?
Im using access 2002, when i type dim DB as , database doesnt show up in the list. any ideas?
Thanks