Display record on main form that was selected on a popup

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a main form that displays a bunch of employee information that comes from various tables. I also have a pop up form that allows me to edit employee demographics or add an employee. I'd like to set up the forms such that if I'm working on a particular employee on the pop up, that when I exit that pop up, the main form is now displaying that same employee (regardless of which employee was selected before going to the pop up)

Thanks for any help
Kenny
 
This example assumes:
- the other form is named "frmEmployee", as is open;
- the popup form has a text box named "EmployeeID", which matches the
EmployeeID autonumber field on frmEmployee.

The code sames the record in the employee form if necessary, then tries to
find the matching record in the form's RecordsetClone, and if found moves
the form to that employee.

Dim frm As Form
If Not IsNull(Me.[EmployeeID]) Then
Set frm = Forms("frmEmployee")
If frm.Dirty Then 'Save any edits
frm.Dirty = False
End If
With frm.RecordsetClone
.FindFirst "[EmployeeID] = " & Me.[EmployeeID]
If Not .NoMatch Then
frm.Bookmark = .Bookmark
End If
End With
End If
Set frm = Nothing

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Kenny said:
I have a main form that displays a bunch of employee information that
comes from various tables. I also have a pop up form that allows me to edit
employee demographics or add an employee. I'd like to set up the forms such
that if I'm working on a particular employee on the pop up, that when I exit
that pop up, the main form is now displaying that same employee (regardless
of which employee was selected before going to the pop up).
 
Kenny said:
I have a main form that displays a bunch of employee information that
comes from various tables. I also have a pop up form that allows me to edit
employee demographics or add an employee. I'd like to set up the forms such
that if I'm working on a particular employee on the pop up, that when I exit
that pop up, the main form is now displaying that same employee (regardless
of which employee was selected before going to the pop up).
Thanks for any help.
Kenny

Hi Kenny

Put this function in the main form's module (replacing EmployeeID with
whatever your ID is called):

Public Sub GotoEmployee(ByVal EmployeeID As Integer)
On Error Resume Next
With Me.RecordsetClone
.FindFirst "[EmployeeID] = " & EmployeeID
Me.Bookmark = .Bookmark
End With
End Sub

You can call this from the pop up.
If by "exit that pop up" you mean close the pop up, then you can call the
function in the Close event of the pop up form:

Private Sub Form_Close()
If IsNull(Me.EmployeeID) = False Then
Forms!frmMain.GotoEmployee Me.EmployeeID
End If
End Sub

Regards - Joe
 
Back
Top