Control Button to "obey" combo?

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

Guest

Thanks in Advance!
I have a combo box that searches for an employee name.
I'd like to have a control button bring up the record for the chosen name in
the combo box.

Let's assume that the table where the names and data are stored is called
"mytable" and the combobox is called
"mycombo"

What do I do next to make the new command button "read" the combo selection
and go to that record?

Thanks a million!
 
Stilla,

Use the optional Where clause with the OpenForm method. See VBA Help for
further information.

DoCmd.OpenForm "YourForm", , ,"YourKeyField = " & Me![YourComboBox]

Hope that helps.
Sprinks
 
Thanks in Advance!
I have a combo box that searches for an employee name.
I'd like to have a control button bring up the record for the chosen name in
the combo box.

Let's assume that the table where the names and data are stored is called
"mytable" and the combobox is called
"mycombo"

What do I do next to make the new command button "read" the combo selection
and go to that record?

Thanks a million!

I would do it differently. No Command Button.
Add a combo box to your form header. Use the Combo Wizard.
Select the 3rd option on the first page of questions, something like
"Find a record ..etc.."

When completed, find the employee in the combo box and it will
automatically display that employee's record on the form.

Note: You asked to find the employee name, but it would be wiser to
find the EmployeeID as it's not uncommon to have more that one
employee with the same first and last names. Include the EmployeeID,
EmployeeName, and perhaps Department in the combo box. Just have the
wizard hide the EmployeeID column and display the Name and Department
column. You'll be asked.
 
Dear Sprinks,

Thanks for the answer. I inserted your code into the button event procedure
code, and now have the following (but returns and "object required" error).
Excuse my ignorance, but this is my very first Access project. Could you
troubleshoot the code?

Private Sub Findcontact_button_Click()
On Error GoTo Err_Findcontact_button_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "INTERVIEW FORM"
CoCmd.OpenForm "INTERVIEW FORM", , , "Contact_Name = " &
Me![Contactnamecombo]

Exit_Findcontact_button_Click:
Exit Sub

Err_Findcontact_button_Click:
MsgBox Err.Description
Resume Exit_Findcontact_button_Click

End Sub

Sprinks said:
Stilla,

Use the optional Where clause with the OpenForm method. See VBA Help for
further information.

DoCmd.OpenForm "YourForm", , ,"YourKeyField = " & Me![YourComboBox]

Hope that helps.
Sprinks


Stilla said:
Thanks in Advance!
I have a combo box that searches for an employee name.
I'd like to have a control button bring up the record for the chosen name in
the combo box.

Let's assume that the table where the names and data are stored is called
"mytable" and the combobox is called
"mycombo"

What do I do next to make the new command button "read" the combo selection
and go to that record?

Thanks a million!
 
Back
Top