A
Andrew
I have a combo box that is populated with data from a query. I have the
properties of the combo box set so that entries do not have to be from the
list. However...
If the entry chosen is NOT from the list then I would like an alert to appear
asking the user if they really want to add to the list or re-type their entry.
Following instructions on another post, I've linked the combo box to an event
procedure. The code is below. But nothing is happening.
Please advise on where I am going wrong.
Thanks in advance,
Andrew
Option Compare Database
'************ 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 SchoolT1_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 a school in the list " & vbCrLf &
vbCrLf
strMsg = strMsg & "Do you want to add the new school to the current list?
"
strMsg = strMsg & vbCrLf & vbCrLf & "Click Yes to link or No to re-type
it."
If MsgBox(strMsg, vbQuestion + vbYesNo, "Add new school?") = vbNo Then
Response = acDataErrContinue
Else
Set db = CurrentDb
Set rs = db.OpenRecordset("table1", dbOpenDynaset) ' must define
table name
On Error Resume Next
rs.AddNew
rs!School = NewData 'must define field name
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
properties of the combo box set so that entries do not have to be from the
list. However...
If the entry chosen is NOT from the list then I would like an alert to appear
asking the user if they really want to add to the list or re-type their entry.
Following instructions on another post, I've linked the combo box to an event
procedure. The code is below. But nothing is happening.
Please advise on where I am going wrong.
Thanks in advance,
Andrew
Option Compare Database
'************ 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 SchoolT1_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 a school in the list " & vbCrLf &
vbCrLf
strMsg = strMsg & "Do you want to add the new school to the current list?
"
strMsg = strMsg & vbCrLf & vbCrLf & "Click Yes to link or No to re-type
it."
If MsgBox(strMsg, vbQuestion + vbYesNo, "Add new school?") = vbNo Then
Response = acDataErrContinue
Else
Set db = CurrentDb
Set rs = db.OpenRecordset("table1", dbOpenDynaset) ' must define
table name
On Error Resume Next
rs.AddNew
rs!School = NewData 'must define field name
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