 |
aalto Level: Graduate
 Registered: 21-08-2009 Posts: 10
|
VB 2008 Express combobox & duplicate entries from access database
My problem is that the Access database linked to VB 2008 has duplicate items in several columns, which, when attached to comboboxes, are all displayed (eg. 1,1,1,2,2,2,3,3,3 instead of 1,2,3). I want to keep all records, which will be filtered down to a single part number in a text box....any ideas how to start please?
|
|
21-08-2009 at 12:44 PM |
|
|
aalto Level: Graduate
 Registered: 21-08-2009 Posts: 10
|
Re: VB 2008 Express combobox & duplicate entries from access database
Thanks for your help GeoffS.
I've tried clicking on the combobox and adding the code you suggested, but it doesn't seem to work for me (errors are displayed).
I'm certain this is down to my total lack of knowledge where VB 2008 Express is concerned.
At the moment I have a Form that is connected to an Access database. There are 5 comboboxes. I've attached them to the datasource and specified the column, but they seem to act independently as well as showing all values from the database (including duplicates).
I need to only show single values in comboboxes....sorry, but I may need step by step, if possible - any help at all would be appreciated.
Thanks
aalto
|
|
24-08-2009 at 02:41 PM |
|
|
aalto Level: Graduate
 Registered: 21-08-2009 Posts: 10
|
Re: VB 2008 Express combobox & duplicate entries from access database
GeoffS, thanks very much for the help and great, it works....for the first combobox.
Below is outlined what I hope to achieve for the whole vb form:
I have an access database table with 10 columns, that is linked and setup as the datasource for my VB Form1. From the VB Data Source list, I've dragged the first 5 of the listed database columns onto the form as ComboBoxes, the next 3 are dragged on as 3 separate groups of RadioButtons (there are only 2 different entries in each of these 3 columns). The final 2 columns are placed as text boxes and will display data established by options selected from the previous boxes etc.
There are duplicate entries in all database columns - I need each ComboBox to show every database value, but only once (no duplicates). The process for using Form1 may be as follows:
ComboBox1 - select value
ComboBox2 - select value
ComboBox3 - select value
ComboBox4 - select value
ComboBox5 - select value
RadioButton1 - selected
RadioButton2 - unselected
RadioButton3 - unselected
RadioButton4 - selected
RadioButton5 - selected
RadioButton6 - unselected
TextBox1 - value displayed
TextBox2 - value displayed
When RadioButton1 & RadioButton2 are reached, based on the selection made in ComboBox4, it maybe that RadioButton1 is the only option available for RadioButton1 & RadioButton2.
The end user would not be able to add or modify database entries, I just want the Form to configure and display data based on the selected options.
Do you know if I'd need to set up individual queries in Access for each combobox required, or just setup all coulmns in the single query....or is there another way of doing this.
Thanks
aalto
|
|
25-08-2009 at 02:24 PM |
|
|
GeoffS Level: VB Lord

 Registered: 29-09-2004 Posts: 606
|
Re: VB 2008 Express combobox & duplicate entries from access database
aalto - It's a bit difficult to answer your question without knowing a bit more about the data you are trying to retrieve and what you are then going to do with it.
It sounds to me as if you are going to retrieve an object value that is based upon the selection of certain criteria, but you appear to be getting it all from one table which presumably lists the criteria of each object. This would explain why you are having trouble dealing with duplicate entries for each of the criteria. This is bad database design as you are storing information more than once. What you should do is create seperate tables for the criteria (which will then supply the lists in your ComboBoxes) and then store the criteria Index in your main table. It is then easy to create a query to find objects in the table that have all the desired criteria.
Maybe an example would help here :-
A hotel has a number of bedrooms, they vary according to the type of room, and the view from the room. You create a table "RoomTypes" with columns "RoomTypeID" which is your Primary Key, and "RoomType" which is a text description. Entries here might be 1,Single 2,Double 3,Twin
You then create a table "RoomViews" with columns "RoomViewID" which is your Primary Key, and "RoomView" which again is a text description. Entries here might be 1,Sea 2,Pool 3,Dustbins
You then create your main table - "Rooms" with columns "RoomID" which is your Primary Key, "RoomNumber", "RoomTypeID", "RoomViewID"
where you store information on the rooms in the hotel - so one entry would look like :- 1,126,2,3
You see, storing the PrimaryKey numbers of the criteria takes up much less space than continually storing the Strings "Double" and "Dustbins"
Your ComboBoxes are set so that :-
ComboRoomTypes.DataSource = "RoomTypes"
ComboRoomTypes.DisplayMember = "RoomType"
ComboRoomTypes.ValueMember = "RoomTypeID"
and the same with the Views Combo.
Then when a user selects from the Combos retrieve the SelectedValue into a Variable :
lngRoomTypeID = ComboRoomTypes.SelectedValue
So to find all rooms of the selected type and a Sea View the query would be : "SELECT RoomNumber FROM Rooms WHERE ((RoomTypeID = " & lngRoomTypeID & ") AND (RoomViewID = 1))"
I hope that helps a bit with what you are trying to achieve.
____________________________
multi-tasking - the ability to hang more than one app. at the same time.
|
|
26-08-2009 at 02:18 PM |
|
|
aalto Level: Graduate
 Registered: 21-08-2009 Posts: 10
|
Re: VB 2008 Express combobox & duplicate entries from access database
Hello again GeoffS, thanks very much for your in-depth response. Yes, I believe that the table structure you've outlined is the correct way to proceed.
I've split the original table into 10 separate ones, within an Access database.
I have linked the comboboxes to the correct tables and they do show the correct drop down values, but at the moment act independently.
That's as far as I can understand. Sorry to be a pain, but could you please help me with the next step concerning the code/query....do I just double click on a combobox and start adding the code....it didin't seem to recognise the column names in my tables.
In my form I will then have 3 sets of radio buttons (as mentioned in my previous email). Each set has 2 buttons, which will be linked to a table - each representing 1 of 2 values in the corresponding table.....do you know how I set these up?
There is then a final text box which will reflect what's in the master table, containing all of the ID references for the previous tables. This text box will just display a number (hopefully calculated from the previous boxes etc).
Once again, your help would be really appreciated.
Thanks
aalto
|
|
27-08-2009 at 11:45 AM |
|
|
aalto Level: Graduate
 Registered: 21-08-2009 Posts: 10
|
Re: VB 2008 Express combobox & duplicate entries from access database
Hello again GeoffS
Thanks, I managed to workout how to set the buttons up by grouping, but again, my problem/lack of understanding is with how to use/link Code to items/databases.
I have looked at a number of examples from websites and ebooks, but they don't seem to be too relevant or specific....I would have thought that what I'm trying to do below would be quite a common setup.
Sorry if I'm repeating myself, but I'm in this situation:
I have 11 Access tables, 10 of which each have 2 columns (a unique ID keys and unique corresponding entry). In the 11th table, each column represents the ID Key from each of the previous 10 tables. There is a final column in table 11, which contains Part Numbers.
Table 11 contains all of the combinations possible - 1500 entries, which result in only 12 different Part Numbers. Therefore, there will be a lot of duplicate entries in table 11.
Each of the 1st 10 tables are linked to seperate Comboboxes, which contain the entries from the 2nd column of the 10 tables.
Table 11 is linked to a Textbox, which will just display a part number.
The idea is that when the form is opened, all entries displayed are blank. Any of the 10 Comboboxes can be selected and the option selected. Depeneding on what value is selected, will effect what corresponding values are displayed in the next selection available from another Combobox. This will go on until all selections have been made from all of the Comboboxes. Only then will a Part Number appear in the final Text box.
I've set up all tables in VB 2008 Express and can get them to display correctly in each Combobox and Textbox. The problem I have is linking the tables / Comboboxes so that each previous selection from a Combobox will limit the options available from the next Combobox.
Can anyone please help, I feel like I'm going around in circles?
Thanks
aalto
|
|
02-09-2009 at 01:40 PM |
|
|
aalto Level: Graduate
 Registered: 21-08-2009 Posts: 10
|
Re: VB 2008 Express combobox & duplicate entries from access database
Thanks for the swift response GeoffS...I'll give what you suggest a go.
aalto
|
|
02-09-2009 at 02:52 PM |
|
|
aalto Level: Graduate
 Registered: 21-08-2009 Posts: 10
|
Re: VB 2008 Express combobox & duplicate entries from access database
Sorry to be a pain GeoffS
I feel quite stupid, but I really need to take things step by step.
With reference to previous emails, I have a form with the correct layout (combo boxes etc).
I have linked the access database as the datasource.
I can get the 1st Pressure combobox to display values from the Pressure table in the Access database.
From there, I'm a bit confused - I'm uncertain where to put code etc to generate the next combobox (based on the selection made from the 1st combobox).
Thanks
aalto
|
|
03-09-2009 at 09:42 AM |
|
|
GeoffS Level: VB Lord

 Registered: 29-09-2004 Posts: 606
|
Re: VB 2008 Express combobox & duplicate entries from access database
aalto - As I said before, you cannot display a selection from a table based on chosen criteria by simply setting the table as the data source for the ComboBox - you will always get all records from the table that way.
If I understand you correctly your first ComboBox is Pressure, and based on the selection you then want to display only certain entries from the Dia table - but that table does not appear to contain any field on which you would filter the selection. If the Combo is to display only certain diameters then you need a way to select the ones that you want to make available in the combo. For example, if a certain pressure can only pass through a hose with certain diameters, then you need 2 extra fields in the Dia table - MinPressureID and MaxPressureID, which would hold the corresponding PressureID's. Then using my DataModule example you would build the SQL Query for the DiaCombo as :-
"SELECT Dia.DiaID, Dia.Dia FROM Dia WHERE (Dia.MinPressureID <= " & intPressureID & ") AND (Dia.MaxPressureID >= " & intPressureID & ")"
You pass the parameter "intPressureID" from your form in the "SelectedIndexChanged" Event of Combo1 to the DataModule and then use the returned DataSet to set the DataSource, DisplayMember, and ValueMember of the 2nd. ComboBox in the same way as my previous example.
Apply that principle to all ComboBoxes, then at the end you would have a Function in the DataModule to which you pass all the chosen values and which would build the SQL Query to return the Part Number.
There is an alternative method to this where the Data "Module" would be a "Class" which would have Properties corresponding to the selection values, so you only pass the value once when setting the Property of the Class. Some might argue that this would be a "Better" way of doing things, but at this stage I think we need to keep things as simple as possible.
Hope that helps.
____________________________
multi-tasking - the ability to hang more than one app. at the same time.
|
|
03-09-2009 at 11:53 AM |
|
|
|
|
 |
 |