K
kheisler6
I have a main form (frmPatients) with a subform (fsubReferrals), with a
subform (fsubPeople).
For each referral, the user uses a continuous subform to add people
related to the referral. To do this, I would like the user to:
1. Click an "Add Person to Referral" button on a new record in the
subform
2. Have a popup box appear which allows him to first search (by last
name) to see if the person exists (everyone in tblPeople is listed in a
listbox on the popup form).
...... 2a. If he finds the person, I'd like him to be able to
highlight the name, hit a "Select" button on the popup, and have
that person passed to the appropriate record on the subform.
...... 2b. If he doesn't find the person, I'd like him to click an
"Add New Person" button on the popup, enter info about the new
person, and then have that person passed to the appropriate record on
the subform.
A combo box with NotInList code could to do this, but the popup box
approach will allow me to add some additional features and options for
the user.
Every thing works up to the point when - if he finds the person
he's looking for in the popup search box and hits the Select button
- it says "Person Not Found" (part of my code)
Every thing is modeled after the nifty ExpandingSearch2K download
available at http://www.datastrat.com/Download2.html.
Thanks for any advice. - Kurt
CODE BELOW:
Code for "Add Person to Referral" button (a button on each record
of the continuous subform, fsubPeople):
Private Sub cmdAddPersonToReferral_Click()
Dim lngPersonID As Long
lngPersonID = GetPersonID 'GetPersonID is a public function,
listed below
If lngPersonID <> 0 Then
Dim rs As Recordset
Dim db As Database
Dim criteria As String
Set db = CurrentDb()
Set rs = Me.RecordsetClone
criteria = "[PersonID] =" & lngPersonID
rs.FindFirst criteria
If Not rs.NoMatch Then
Me.Bookmark = rs.Bookmark
Else
MsgBox "Person Not Found"
End If
Me.Refresh
End If
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
Exit Sub
End Sub
-----------------------------------------------------------------
Public Function GetPersonID() As Long
lngPersonIDSelect = 0
DoCmd.OpenForm "frmAddPeopleToReferral" 'This is the popup box
Do While lngPersonIDSelect = 0
DoEvents
Loop
If lngPersonIDSelect = -1 Then
lngPersonIDSelect = 0
End If
GetPersonID2 = lngPersonIDSelect
Exit Function
End Function
-----------------------------------------------------------------
Code for "Select" button on popup form, after user has highlighted
the name
If Not IsNull(Me![lstResults].Column(0)) Then
lngPersonIDSelect = Me![lstResults].Column(0)
DoCmd.Close
Else
MsgBox "Select a name or press cancel."
End If
Exit Sub
End Sub
subform (fsubPeople).
For each referral, the user uses a continuous subform to add people
related to the referral. To do this, I would like the user to:
1. Click an "Add Person to Referral" button on a new record in the
subform
2. Have a popup box appear which allows him to first search (by last
name) to see if the person exists (everyone in tblPeople is listed in a
listbox on the popup form).
...... 2a. If he finds the person, I'd like him to be able to
highlight the name, hit a "Select" button on the popup, and have
that person passed to the appropriate record on the subform.
...... 2b. If he doesn't find the person, I'd like him to click an
"Add New Person" button on the popup, enter info about the new
person, and then have that person passed to the appropriate record on
the subform.
A combo box with NotInList code could to do this, but the popup box
approach will allow me to add some additional features and options for
the user.
Every thing works up to the point when - if he finds the person
he's looking for in the popup search box and hits the Select button
- it says "Person Not Found" (part of my code)
Every thing is modeled after the nifty ExpandingSearch2K download
available at http://www.datastrat.com/Download2.html.
Thanks for any advice. - Kurt
CODE BELOW:
Code for "Add Person to Referral" button (a button on each record
of the continuous subform, fsubPeople):
Private Sub cmdAddPersonToReferral_Click()
Dim lngPersonID As Long
lngPersonID = GetPersonID 'GetPersonID is a public function,
listed below
If lngPersonID <> 0 Then
Dim rs As Recordset
Dim db As Database
Dim criteria As String
Set db = CurrentDb()
Set rs = Me.RecordsetClone
criteria = "[PersonID] =" & lngPersonID
rs.FindFirst criteria
If Not rs.NoMatch Then
Me.Bookmark = rs.Bookmark
Else
MsgBox "Person Not Found"
End If
Me.Refresh
End If
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
Exit Sub
End Sub
-----------------------------------------------------------------
Public Function GetPersonID() As Long
lngPersonIDSelect = 0
DoCmd.OpenForm "frmAddPeopleToReferral" 'This is the popup box
Do While lngPersonIDSelect = 0
DoEvents
Loop
If lngPersonIDSelect = -1 Then
lngPersonIDSelect = 0
End If
GetPersonID2 = lngPersonIDSelect
Exit Function
End Function
-----------------------------------------------------------------
Code for "Select" button on popup form, after user has highlighted
the name
If Not IsNull(Me![lstResults].Column(0)) Then
lngPersonIDSelect = Me![lstResults].Column(0)
DoCmd.Close
Else
MsgBox "Select a name or press cancel."
End If
Exit Sub
End Sub