healermoon
IS-IT--Management
I can add a new company without the msgbox popping up to say this isn't on the list are you sure you want to add it? I would like it to ask to keep misspellings etc out of the list. I used Dev Ashish's code with my own fld name, and table name:
' ************ Code Start **********
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Sub fldCustName_NotInList(NewData As String, Response As Integer)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strMsg As String
strMsg = "'" & NewData & "' is not an available Company Name " & vbCrLf & vbCrLf
strMsg = strMsg & "Do you want to add a new Company Name?"
strMsg = strMsg & vbCrLf & vbCrLf & "Click Yes to link or No to re-type it."
If MsgBox(strMsg, vbQuestion + vbYesNo, "Add new name?") = vbNo Then
Response = acDataErrContinue
Else
Set db = CurrentDb
Set rs = db.OpenRecordset("tblCust", dbOpenDynaset)
On Error Resume Next
rs.AddNew
rs!fldCustName = NewData
rs.Update
If Err Then
MsgBox "An error occurred. Please try again."
Response = acDataErrContinue
Else
Response = acDataErrAdded
End If
End If
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
'*********** Code End **************
Is is a matter of changing fldCustName to cbxCustName? I don't know why it isn't working. Please help.
Thanks-
Kenny Renaud
IT Manager
Corral West Ranchwear Inc.
' ************ Code Start **********
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Sub fldCustName_NotInList(NewData As String, Response As Integer)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strMsg As String
strMsg = "'" & NewData & "' is not an available Company Name " & vbCrLf & vbCrLf
strMsg = strMsg & "Do you want to add a new Company Name?"
strMsg = strMsg & vbCrLf & vbCrLf & "Click Yes to link or No to re-type it."
If MsgBox(strMsg, vbQuestion + vbYesNo, "Add new name?") = vbNo Then
Response = acDataErrContinue
Else
Set db = CurrentDb
Set rs = db.OpenRecordset("tblCust", dbOpenDynaset)
On Error Resume Next
rs.AddNew
rs!fldCustName = NewData
rs.Update
If Err Then
MsgBox "An error occurred. Please try again."
Response = acDataErrContinue
Else
Response = acDataErrAdded
End If
End If
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
'*********** Code End **************
Is is a matter of changing fldCustName to cbxCustName? I don't know why it isn't working. Please help.
Thanks-
Kenny Renaud
IT Manager
Corral West Ranchwear Inc.