Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Move to a record

Status
Not open for further replies.

mystuff

Programmer
Apr 30, 2004
86
0
0
US
This seems ridiculously easy, but I can't figure it out. I have a form with Workstation information (Key is WorkstationID). One of the fields in the record is EmployeeID. I have an unbound combo box (cboEmployee) for Employees (key is also EmployeeID). When the user selects and employee in the combo box, I'd like the Form to go to the first Workstation record for that person (EmployeeID = cboEmployee).

I searched but everything talks about subforms. This is not a subform, it is just a main form.

Thanks.
 
Two options i can think of:

1) Change the forms recordsource on the combo box change.
Code:
Private Sub cboEmployee_Change()
    Me.RecordSource = "SELECT * FROM tblWhatever WHERE EmployeeID = '" & cboEmployee.Value & "';"
    Me.Refresh
End Sub

2) Cycle through your recordset till you get to it.
Code:
Private Sub cboEmployee_Change()
    Me.RecordSet.MoveFirst
    Do until EmployeeID = cboEmployee or Me.RecordSet.EOF
        Me.RecordSet.MoveNext
    Loop
End Sub

The first option is the quickest, but it will only show the values for that single employee and will only change after you select a new employee.



-Pete
 
How are ya mystuff . . .

When you [blue]instantiate a new combobox[/blue], you should be able to what you want by selecting the 1st option ([blue]I want the combo box to loop up the values in a table or query[/blue]) and following the wizard . . .

Calvin.gif
See Ya! . . . . . .
 
I assume the bound column of the combo is the ID column.
In the AfterUpdate event procedure of cboEmployee:
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClose
rs.FindFirst "EmployeeID=" & Me!cboEmployee
If rs.NoMatch Then
MsgBox "no record found for tha employee"
Else
Me.Bookmark = rs.Bookmark
End If
Set rs = Nothing

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
And just for the record....

Me.EmployeeID.SetFocus
Docmd.FindRecord Me!cboEmployee


If WorkStation, is another form...

Docmd.OpenForm "WorkStation"
Forms!workstation!EmployeeID.SEtFocus
Docmd.FindRecord Me!cboEmployee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top