R
rebecky via AccessMonster.com
Hello. I am trying to handle the apostrophes during this NotInList event:
I cannot get it right and am at my wits end.
Any ideas?
Thanks!
Private Sub ContactID_NotInList(NewData As String, Response As Integer)
Dim Result
Dim Msg As String
Dim CR As String ' Carriage Return
'Title = "TED version 2.1"
CR = vbCrLf
' Return Control object that points to combo box.
Dim ctl As Control
Set ctl = Me![ContactID] 'An alias for the name of this combo-box,
whichreduces typing.
' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub
NewData = StrConv(NewData, vbProperCase) ' Converts new entry to ProperCase.
' Ask the user if he or she wishes to add the new contact.
Msg = ""
Msg = Msg & "'" & NewData & "' is not in TED Site Contacts" & CR & CR
Msg = Msg & "Do you want to add this Site Contact?"
DoCmd.SetWarnings False
If MsgBox(Msg, vbQuestion + vbYesNo, "TED version 2.1") = vbYes Then
' Set Response argument to indicate that data is being added.
strSql = "INSERT INTO [tblsitecontacts] (contactname) " & _
"VALUES ('" & NewData & " & Chr$(34)"" & Me![ContactName] &
Chr$(34)"");"
DoCmd.RunSQL strSql
intAnswer = Nz(DMax("[contactID]", "[tblsitecontacts]"), 0)
MsgBox "The new Contact" & CR & NewData & " was Added. Please select
" & NewData & " from the List and continue Entering " & NewData & "
Information or Use the Undo Button" _
, vbInformation, "TED version 2.1"
Response = acDataErrAdded
'** MUST ** undo entry first, or you get "Can't go to specified record"
'DoCmd.GoToRecord , , acNewRec
ctl.Undo
DoCmd.RunCommand acCmdSaveRecord
'Supress error message
Response = acDataErrContinue
Else
'User clicked the No button here.
'You could display a message to "try again", but that just annoys mostof
us.
'Supress error message
Response = acDataErrContinue
ctl.Undo
SendKeys "{ESC}"
Exit Sub
End If
Set ctl = Nothing ' ANY time you use "Set", you should "unset" it
beforeleaving.
'ErrContinue
Me.ContactID.Requery
I cannot get it right and am at my wits end.
Any ideas?
Thanks!
Private Sub ContactID_NotInList(NewData As String, Response As Integer)
Dim Result
Dim Msg As String
Dim CR As String ' Carriage Return
'Title = "TED version 2.1"
CR = vbCrLf
' Return Control object that points to combo box.
Dim ctl As Control
Set ctl = Me![ContactID] 'An alias for the name of this combo-box,
whichreduces typing.
' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub
NewData = StrConv(NewData, vbProperCase) ' Converts new entry to ProperCase.
' Ask the user if he or she wishes to add the new contact.
Msg = ""
Msg = Msg & "'" & NewData & "' is not in TED Site Contacts" & CR & CR
Msg = Msg & "Do you want to add this Site Contact?"
DoCmd.SetWarnings False
If MsgBox(Msg, vbQuestion + vbYesNo, "TED version 2.1") = vbYes Then
' Set Response argument to indicate that data is being added.
strSql = "INSERT INTO [tblsitecontacts] (contactname) " & _
"VALUES ('" & NewData & " & Chr$(34)"" & Me![ContactName] &
Chr$(34)"");"
DoCmd.RunSQL strSql
intAnswer = Nz(DMax("[contactID]", "[tblsitecontacts]"), 0)
MsgBox "The new Contact" & CR & NewData & " was Added. Please select
" & NewData & " from the List and continue Entering " & NewData & "
Information or Use the Undo Button" _
, vbInformation, "TED version 2.1"
Response = acDataErrAdded
'** MUST ** undo entry first, or you get "Can't go to specified record"
'DoCmd.GoToRecord , , acNewRec
ctl.Undo
DoCmd.RunCommand acCmdSaveRecord
'Supress error message
Response = acDataErrContinue
Else
'User clicked the No button here.
'You could display a message to "try again", but that just annoys mostof
us.
'Supress error message
Response = acDataErrContinue
ctl.Undo
SendKeys "{ESC}"
Exit Sub
End If
Set ctl = Nothing ' ANY time you use "Set", you should "unset" it
beforeleaving.
'ErrContinue
Me.ContactID.Requery