473,387 Members | 3,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Record lookup with 2 Combo boxes

Hi all. I working with an existing access DB at my job and have been asked to add some forms and queries. I've been doing well so far, but this last part of the project has got me stuck.

My question is I am trying to create a form to look up a record based off of the selections in 2 combo boxes. ComboBox1 is a list of customer ID's and ComboBox2 is a list of products based off the selection of the customer ID. ComboBox1 is from the Customers table and ComboBox2 is from the Requirements table.

I would like the fields in my Form to populate with the information from the appropriate record based off of the 2 combo boxes, i.e. Customer is chosen from ComboBox1, ProductID is chosen from ComboBox2 and then the record appears in the textboxes.

I have tried making the form bound to a query or table but when I do this I am either not able to get any records to populate the fields or when i open in the form I can't see any of the controls.

I'm not really sure what I'm doing wrong, but it's pretty frustrating.

Thanks for any help :)
Oct 3 '10 #1
10 5706
Mr Key
132 100+
Hi!
See the attached database in the post to follow
Oct 3 '10 #2
Mr Key
132 100+
You may use this attached 2Combobox to select your records. COMBO1(Lname)Rowsource=SELECT [Details].[CustomerID], [Details][Lname] FROM Details; and COMBO2 (CustomerID) RowSource=SELECT [Products].[ProductID], [Products].[CustomerID], [Products].[ProductName] FROM Products WHERE Forms!Details!CustomerID=[Products].[CustomerID]; I have include refresh button to look for the latest data in the records. I hope this might solve your problem.
Mark it as answered incase it has or you may ask for more clarifications
You are welcome!!!
Open the attachment below
Attached Files
File Type: zip 2CombosonForms.zip (31.1 KB, 538 views)
Oct 3 '10 #3
BarbQb
31
Hi Mr Key, thanks for the help. I only have Access 2003 so I am not able to open the attached DB.
Oct 4 '10 #4
Mr Key
132 100+
Let me send it in 2003 format.mdb
Attached Files
File Type: zip 2CombosonForms1.zip (32.5 KB, 208 views)
Oct 4 '10 #5
BarbQb
31
Hi Mr Key. For some reason my computer won't open the new attachment, but I was able to get everything working from the Rowsource info you put in your post.

VBA turns out like this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Toy_AfterUpdate()
  2.  
  3. Me.Refresh
  4.  
  5.     ' Find the record that matches the control.
  6.     Dim rs As Object
  7.  
  8.     Set rs = Me.Recordset.Clone
  9.     rs.FindFirst "[TOY_ID] = '" & Me![Toy] & "'"
  10.     If Not rs.EOF Then Me.Bookmark = rs.Bookmark
  11. End Sub

I put this in for the refresh, I don't know if you had anything different.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Customer_Click()
  2. Me.Refresh
  3. End Sub
Oct 4 '10 #6
Mr Key
132 100+
You should have two forms, Main form and its Subform, Combobox 1 at main form and Combobox2 at SubForm, If you choose record source from two different tables without explicity point out the records source; you may endup with no records.
Set your mainform RecordSource to tblCustomer and SubForm to tblProducts and then set the following:
1. Customers_Combo
RowSource=SELECT [Details].[CustomerID], [Details].[Lname] FROM Details; and
AfterUpdate Event is a Macrofor RecordSearch (VBA may do also)
2. Products_Combo
RowSource=SELECT [Products].[ProductID], [Products].[CustomerID], [Products].[ProductName] FROM Products WHERE Forms!Details!CustomerID=[Products].[CustomerID];
and AfterUpdate event SearchforRecords in this SubForm
3. This system will works only once without RefreshButton, You may use any code or Macro to Refresh the records so that to update Products_Combo, otherwise you will endup with no recordschange in the Subform.
4. This approach is valid only if you have form and Subform otherwise you might use other approach to handle this.
Oct 4 '10 #7
BarbQb
31
Thanks again Mr Key.

I was able to get the two combo boxes to work off of one form. The form is bound to the second table.

Below are the steps I took:

ComboBox2 is based off of the selection from ComboBox1

COMBO1 Rowsource
SELECT [Table1].[Customer], [Table1].[CustomerID]
FROM Details;

Make the form bound to Table2

Create 2nd combo box
Choose: I want this to look up a record


Edit Rowsource
COMBO2 RowSource
SELECT [Table2].[ProductID], [Table2].[CustomerID]
FROM Table2
WHERE Forms!FormName!Combo1=[Table2].[CustomerID]
ORDER BY [Table2].[ProductID];


Edit VBA

Expand|Select|Wrap|Line Numbers
  1. Private Sub Control_AfterUpdate()
  2. Me.Refresh
  3. ' Find the record that matches the control.
  4. Dim rs As Object
  5. Set rs = Me.Recordset.Clone
  6. rs.FindFirst "[Product_ID] = '" & Me![Product] & "'"
  7. If Not rs.EOF Then Me.Bookmark = rs.Bookmark
  8. End Sub
Oct 5 '10 #8
Mr Key
132 100+
Yes its, what important here is a REFRESH part of a form. No refresh no records update no solution.
Gooday!
Oct 5 '10 #9
NeoPa
32,556 Expert Mod 16PB
Check out Cascaded Form Filtering. There are examples there too.

PS. Refresh will generally not be of any great help. .Requery is required to get any new records. Check out the difference in Access Help.
Oct 5 '10 #10
Mr Key
132 100+
Yep, nice article
Oct 6 '10 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: William Wisnieski | last post by:
Hello Everyone, Access 2000 I've created a bound form to a table. I've added two lookup combo boxes so the user has a choice of how to look up a record (Individuals or Organizations). The...
3
by: Mindy | last post by:
Does anyone know the difference between Navigational and Lookup features of combo boxes? I wondered if there were difference between these two if we selecte "remember the value for later use" when...
9
by: Edwinah63 | last post by:
Hi everyone, Please let there be someone out there who can help. I have two BOUND combo boxes on a continuous form, the second being dependent on the first. I have no problem getting the...
2
by: jim | last post by:
I have created a Table that has 13 fields and 2 Primary Keys, e.g. 60 1, 60 2, ... 60 28, 61 1, 61 2, ... 61 28, etc... I want to create a Form where I can input the Primary Key values to query...
2
by: Ausclad | last post by:
How Would you implement this? I have an existing Access application that needs to be converted to .net I am restricted to use the existing database design. One of the areas is a timesheet...
7
by: Ausclad | last post by:
Ok, ill try again..... It seems fairly simple. I have two combo boxes in a datagrid. The datagrid is bound to a a table in a dataset. The two combo boxes are bound to a single data table...
1
by: akhenaton | last post by:
I have 6 tables total, 5 of them have two fields, ID and name, like so: Table1 (ID1, name1) Table2 (ID2, name2) .... Table5 (ID5, name5) The last table is an intersection table that brings...
1
by: hawk7890 | last post by:
I created an access database using access 2003 with lookup tables and I am having isues where my combo boxes on the form update the lookup table instead of the master table. I have a query to my...
7
by: Toireasa | last post by:
Hi, Newbie Access developer here, and my first post on this forum, so I might not get everything right - thanks in advance for your help and your patience! I'm using Access 2007, in XP. I'm...
3
by: dblack64 | last post by:
I am working in Access 2007. I have a form named Master Terms List that contains 4 bound text boxes and 7 cascading combo boxes. The bound text boxes have data sources from a table named Termslist. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.