I am currently addressing the findrecord code you sent me. I have my combobox listing all my Assession Numbers including the <Add Record>. I have changes the name of my combobox to cboGoToAssession. So fisrt thing would be to change cboGoToContact_AfterUpdate()
to cboGoToAssession_AfterUpdate(). Next I tried to change Me.FirstName.SetFocus to Me.txtMRN.SetFocus. I then changed .FindFirst "ContactID = " & ctrl to "ID = " & ctrl.
With these changes I get a message when I put a number into the combobox which states "The text you entered isn't an item in the list. Select an iten from the list, or enter text that matcheson of the listed items. Not sure where this message was derived
from.
What I need to do is type in combobox an AssessionNumber, if not in list GoToAssession_NotInList. I am having trouble changing your code to meet my needs. Any help is greatly appreciated.
Thank,
Kerry
Private Sub cboGotoContact_AfterUpdate()
Const MESSAGETEXT = "No matching record"
Dim ctrl As Control
Set ctrl = Me.ActiveControl
If Not IsNull(ctrl) Then
If ctrl = 0 Then
' go to new record and move focus to FirstName control
DoCmd.GoToRecord acForm, Me.Name, acNewRec
Me.FirstName.SetFocus
Else
With Me.RecordsetClone
.FindFirst "ContactID = " & ctrl
If Not .NoMatch Then
' go to record by synchronizing bookmarks
Me.Bookmark = .Bookmark
Else
MsgBox MESSAGETEXT, vbInformation, "Warning"
End If
End With
End If
End If
End Sub
Private Sub cboGotoContact_NotInList(NewData As String, Response As Integer)
Dim ctrl As Control
Dim strMessage As String
Dim strFirstName As String, strLastName As String
Set ctrl = Me.ActiveControl
strMessage = "Add " & NewData & " to list?"
strFirstName = Left(NewData, InStr(NewData, " ") - 1)
strLastName = Mid(NewData, InStr(NewData, " ") + 1)
'if user confirms insert move form to new record
' and insert values into first and last name controls
If MsgBox(strMessage, vbYesNo + vbQuestion) = vbYes Then
Response = acDataErrContinue
ctrl.Undo
DoCmd.GoToRecord acForm, Me.Name, acNewRec
Me.FirstName = strFirstName
Me.LastName = strLastName
Else
Response = acDataErrContinue
ctrl.Undo
End If
End Sub