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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about combo boxes

Status
Not open for further replies.

trifest

Programmer
Sep 5, 2002
52
0
0
US
I have a list of companies in a combo box and I want a user to be able to select a company in the box and the form to go directly to that record with the associated information (Address, phone,etc) I tried doing a filter by passing a condition to the openform command but no luck. thanks for the help.
 
On your form with the company info, you could create a combobox with the companyID. For my example, it's named Findit. On the AfterUpdate event, type:

Private Sub Findit_AfterUpdate
Dim R As Recordset
Set R = Me.RecordsetClone
R.FindFirst "[CompanyID] = " & Char(34) & Me![Findit] & Char(34)
Me.BookMark = R.BookMark
End Sub

Char(34) means " (I got fancy)

Neil
 
What I always do is set up your combo box with the index field (usually called "ID") as the first column, and call it "LookupBox". Then all you need to do is set an On Exit event for Lookup Box:

DoCmd.GoToControl Me.ID.Name
DoCmd.FindRecord Me.LookupBox

That should be all you need.
 
I always forget about those DoCmd commands!
Thanks
Neil
 
can't seem to get it working. it says method or data member not found for the Me![Findit] part of it.
 
Go to Design view. Do ALT+F11 to go to the VBA window. Click on Tools, References. Look for Microsoft DAO 3.6 library (or the latest version). Place a check next to it. Move the library up to about the third or fourth position from the top of the list. Close the window.

Also, make sure you named your combobox Findit.

Neil
 
now i'm getting "object variable or With block variable not set" the combo box is named FindIt
 
*&(*&^ libraries!
Change Dim R As Recordset to Dim R As DAO.Recordset

Check to see that after you type the . you get a dropdown list.


 
no luck with that either. i've never seen this before. but then again i've never worked with DAO's really
 
can't seem to get that to work either. i'm getting the method or data member not found for the .Name part
 
No more fancy stuff. Here's the very basic:
Again create your combobox using the wizard. Then on the AfterUpdate event put:

Dim R As DAO.Recordset
Set R = Me.RecordsetClone
R.FindFirst "[nameID] = " & Me![Findit]
Me.Bookmark = R.Bookmark


Findit is the name of the combobox (click on the combobox itself in design view, bring up its' property sheet, click the ALL tab and scroll to the top to the option Name).
Then click on the event tab and click on After Update. Click on the three dots, select code builder and paste the code.

I know this works, I use it everyday.

Neil
 
that worked perfectly, thanks so much for the help. i thought that's what i had before but apparently not. thanks again everyone
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top