473,473 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

combo box but inputs the wrong value.

9 New Member
hi, please help me on this issue that im facing... I have created a filtered combo box in ms access. It works but the value it inputs in the database is the primary key value like in my program (lngMyID =1) . What i would like to have is the value that 1 represents username.

here is my source code

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboStore_AfterUpdate()
  2. Dim sManagerSource As String
  3. Dim sFunctional As String
  4. Dim sFunctionMade As Variant
  5.  
  6.  
  7. sManagerSource = "SELECT [tblSubCategory].[lngManagerID]," & _
  8.                  "[tblSubCategory].[lngStoreID]," & _
  9.                  "[tblSubCategory].[strSubCategory] " & _
  10.                    "FROM tblSubCategory " & _
  11.                    "WHERE [lngStoreID] = " & Me.cboStore.Value
  12.  
  13.  
  14. Me.cboManager.RowSource = sManagerSource
  15. Me.cboManager.Requery
  16.  
  17.  
  18. End Sub
  19.  
btw this is in reference to this link

http://www.databasedev.co.uk/filter_combo_boxes.html
Sep 19 '07 #1
9 2330
Scott Price
1,384 Recognized Expert Top Contributor
In the properties dialog box for the combobox, check which column is bound. This is the value that will be entered in the database.

So in your SELECT statement, you choose three items, set the bound column to 2, and the second item is what will be entered in the db when selected from the combo box.

As for wanting the UserID/Username to be entered by a choice from what you posted, there's a lot more information that we need in order to understand what you want!

In what you posted, there is no reference to a username anywhere in the Select statement that becomes the combo box row source.

We need a little clearer idea of what you are trying to accomplish.

Regards,
Scott
Sep 19 '07 #2
oriondcv
9 New Member
thanks, what im trying to achieve is to have three combo boxes; first combo box then the second one is dependent on the value of the first and then third one is dependent on the second one.

i got the idea from this website.

http://accessprogrammer.blogspot.com/2005/08/filter-combobox-based-on-another.html

but this one specifies 2 combo boxes. Unfortunately, the one im working on what to have 3 filtered combox and each are dependent on each other.

here are my queries:

first combo box:

SELECT DISTINCT [tblTasks].[strCategory]
FROM tblTasks;

second combo box:

SELECT DISTINCT [tblTasks].[strCategory], [tblTasks].[strSubCategory]
FROM tblTasks
WHERE ((([tblTasks].[strCategory])=[forms]![frm_Projects_and_Tasks].[cboCategory].value));


third combo box

SELECT DISTINCT [tblTasks].[strSubCategory], [tblTasks].[strProductType]
FROM tblTasks
WHERE ((([tblTasks].[strSubCategory])=[forms]![frm_Projects_and_Tasks].[cboSubCat].value));


im having trouble in displaying the third value. cause it is just blank according to my research there is something wrong in the WHERE statement. I have tried to evaluate this but with my little knowledge on the SQL side; im having difficulties on this one.

pls. advice on this and thanks in advance.
Sep 20 '07 #3
Scott Price
1,384 Recognized Expert Top Contributor
Are you using text fields? For example, strSubCategory is a string value?

If so, try changing your cboSubCat.Value to cboSubCat.Text

Regards,
Scott
Sep 20 '07 #4
oriondcv
9 New Member
Now the value keeps on displaying the first value if you choose other option it is still the same 1st value..

Im now trying a different way to input data using this link

http://www.databasedev.co.uk/filter_combo_boxes.html

I have completed the 3rd combo box when I check with the values in the database it displays the number reference in the database [e.g. lngID ]

lngID = 1 (primary number) = Client

What i need is the Client to be input instead of the other number..

Private Sub cboManager_AfterUpdate()

Dim sManagerSource1 As String

sManagerSource1 = "SELECT [tblProduct_Type].[lngManagerID]," & _
"[tblProduct_Type].[lngStoredID]," & _
"[tblProduct_Type].[strProductType] " & _
"FROM tblProduct_Type " & _
"WHERE [lngStoredID] = " & Me.cboManager.Value


Me.cboProduct.RowSource = sManagerSource1
Me.cboProduct.Requery


End Sub


Private Sub cboStore_AfterUpdate()
Dim sManagerSource As String
Dim sFunctional As String
Dim sFunctionMade As Variant


sManagerSource = "SELECT [tblSubCategory].[lngManagerID]," & _
"[tblSubCategory].[lngStoreID]," & _
"[tblSubCategory].[strSubCategory] " & _
"FROM tblSubCategory " & _
"WHERE [lngStoreID] = " & Me.cboStore.Value


Me.cboStore.Value = sFunctionMade

sFunctionMade = DLookup("strCategory", "tblCategory", "[lngStoreID]= cboStore")
MsgBox ": " & cboStore



Me.cboManager.RowSource = sManagerSource
Me.cboManager.Requery


End Sub

Im really trying different ways but to no avail. Thanks again :)
Sep 20 '07 #5
Scott Price
1,384 Recognized Expert Top Contributor
I can see that you are trying, and that is commendable!

Let's stop trying new things for the moment so we can both get on the same page.

You say you want Client to be entered in a table after clicking on the combo box?

Is Client a text/string value or a number value? How is it related to the rest of the information? Is it a field name?

With your three combo boxes, give me an idea of what you are trying to accomplish. What is the flow of the choices... I.e. you choose something in combo box1 then expect what to show in combo box2, after choosing something in combo box2 what do you expect from combo box3?

Regards,
Scott
Sep 20 '07 #6
oriondcv
9 New Member
thanks...

what im trying to accomplish is that when you select a value on the like in my scenario.

1st combo box
2nd combo box will depend on the value that was selected on the first combo box
3rd combo box will depend on the value that was selected on the 2nd combo box.

the declaration for the 1st table

lngStoreID = autonumber
strCategory = text

2nd

lngManagerID = autonumber
lngStoreID = number
lngStoredID = number
strSubCategory

3rd

lngManagerID = autonumber
lngStoredID = number
strProductType = text

the ones in bold are primary keys


what happens is that the value when selecting in the combo box is like

Category = Client, Thin Client
SubCategory = Troubleshooting, etc
ProductType = OS Matters

it capture the details as what is seen in the form. But when you check within the database. It comes as

Category = 1, 21
SubCat = 2
ProductType = 3

The Code im using is:

Private Sub cboManager_AfterUpdate()

Dim sManagerSource1 As String

sManagerSource1 = "SELECT [tblProduct_Type].[lngManagerID]," & _
"[tblProduct_Type].[lngStoredID]," & _
"[tblProduct_Type].[strProductType] " & _
"FROM tblProduct_Type " & _
"WHERE [lngStoredID] = " & Me.cboManager.Value


Me.cboProduct.RowSource = sManagerSource1
Me.cboProduct.Requery


End Sub


Private Sub cboStore_AfterUpdate()
Dim sManagerSource As String
Dim sFunctional As String
Dim sFunctionMade As Variant


sManagerSource = "SELECT [tblSubCategory].[lngManagerID]," & _
"[tblSubCategory].[lngStoreID]," & _
"[tblSubCategory].[strSubCategory] " & _
"FROM tblSubCategory " & _
"WHERE [lngStoreID] = " & Me.cboStore.Value


Me.cboStore.Value = sFunctionMade

sFunctionMade = DLookup("strCategory", "tblCategory", "[lngStoreID]= cboStore")
MsgBox ": " & cboStore

Me.cboManager.RowSource = sManagerSource
Me.cboManager.Requery


End Sub

Im trying to have the details in the database as what is being selected in the combo box :)

Thank you very much
Sep 20 '07 #7
Scott Price
1,384 Recognized Expert Top Contributor
In other words, right now you are seeing a number stored in the table, and instead you want to see the text associated with that number?

Regards,
Scott
Sep 20 '07 #8
oriondcv
9 New Member
yes, it will be hard for us to check one by one on the numbers...

because the combo box seems to work just the output on the database is kinda wrong...
Sep 20 '07 #9
Scott Price
1,384 Recognized Expert Top Contributor
yes, it will be hard for us to check one by one on the numbers...

because the combo box seems to work just the output on the database is kinda wrong...
The combo box setup is actually correct. It is intended to store a foreign key id or primary key id in a table.

From that table you create a query to pull the data (including text) that you wish to see. To do this you just include two tables in the query, the main one with main data, and the secondary one with static data.

I'll give you an example from one of my databases of how this works:

I have a Recipe table with this structure:

Name: tblRecipe
RecipeID AutoNumber Primary Key (PK)
RecipeDesc Text
RecipeName Text
RecipeTypeID Number Foreign Key (FK)

Second table: Name tblRecipeType
RecipeTypeID AutoNumber PK
RecipeType Text

You will notice that in my main table I'm storing a Number that links to my second table's primary key. This is called a foreign key.

In the table tblRecipeType I have this data: Dessert, Main, Breakfast, etc...

Now I create a new recipe, and through a combo box choose Dessert for the recipe type. This stores the number value 2 in my tblRecipe. How do I know what a 2 means?

In a query I do this:
Expand|Select|Wrap|Line Numbers
  1. SELECT tblRecipe.RecipeID, tblRecipe.RecipeName, tblRecipe.RecipeTypeID, tblRecipeType.RecipeType FROM tblRecipe Inner Join tblRecipe ON tblRecipe.RecipeTypeID = tblRecipeType.RecipeTypeID WHERE tblRecipe.RecipeID = Forms!frmRecipeDetail!cboRecipe
When I run this query I get the RecipeID, Recipe Name, Recipe Type ID and Recipe Type (text name) from the chosen Recipe on my form frmRecipeDetail with a combo box called cboRecipe.

Now... Take a good look at your database, and see how the structure is either the same as what I'm referring to, or different than. Then read this tutorial carefully: Database Normalisation and Table Structures

I suspect what is really happening is that you are trying to apply a properly designed combo box setup to an improperly designed database, or are just not understanding how to use the design to display what you want to see.

Regards,
Scott
Sep 20 '07 #10

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

Similar topics

4
by: Heather | last post by:
Hi I am desparately looking for advice in relation to storing the results after selecting items from two combo boxes on a Referral form. The first combo box 'ctl Type' displays a full list of...
0
by: Colleyville Alan | last post by:
I have an app that looks up an id number and when a button is clicked, inputs the id # into a query. After running the query, I click a second button which grabs the client name rather than the id...
2
by: francophone77 | last post by:
Does anyone know how to setup a parameter query, which allows the user to choose from a combo box? TIA
5
by: Ant | last post by:
Hi, (Winform VS2003) I have a combo box bound to a typed data set. When the form loads, the combo box is popluated using a method containing the simple code below: ------------------------...
7
by: sara | last post by:
I have a form where the user selects an item from a list box, and then works on that item. The user chooses an AD, then opens a form to assign departments to the ad. The top of the Depts form has...
5
by: jjyconsulting | last post by:
Newbie needing some help. I have a tblParticipants. The fields include gender, education_level, income, occupation etc., I'm trying to create a form where a user can run a query from the form and...
1
by: lawton | last post by:
Source: this is an access 2003 question My knowledge level: reading books, internet, and trial & error; no formal training I'm trying to get a running sum of what's filtered in a subform which is...
4
by: novoselent | last post by:
This seems like it should be an easy thing, but I think I'm missing something simple here...or I'm just going about it all wrong... Using Access 2003 I have a form that lists vehicle service...
2
by: fredloh | last post by:
i have a table with a yes/no field call "Edited". i have a button that runs code to set the "Edited" field of a selected record to "yes". the code also set the rowsource (using SQL Update and Set...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.