473,789 Members | 2,807 Online
Bytes | Software Development & Data Engineering Community
+ 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 2345
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://accessprogramme r.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_an d_Tasks].[cboCategory].value));


third combo box

SELECT DISTINCT [tblTasks].[strSubCategory], [tblTasks].[strProductType]
FROM tblTasks
WHERE ((([tblTasks].[strSubCategory])=[forms]![frm_Projects_an d_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_bo xes.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_Afte rUpdate()

Dim sManagerSource1 As String

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


Me.cboProduct.R owSource = sManagerSource1
Me.cboProduct.R equery


End Sub


Private Sub cboStore_AfterU pdate()
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.Val ue


Me.cboStore.Val ue = sFunctionMade

sFunctionMade = DLookup("strCat egory", "tblCategor y", "[lngStoreID]= cboStore")
MsgBox ": " & cboStore



Me.cboManager.R owSource = sManagerSource
Me.cboManager.R equery


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_Afte rUpdate()

Dim sManagerSource1 As String

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


Me.cboProduct.R owSource = sManagerSource1
Me.cboProduct.R equery


End Sub


Private Sub cboStore_AfterU pdate()
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.Val ue


Me.cboStore.Val ue = sFunctionMade

sFunctionMade = DLookup("strCat egory", "tblCategor y", "[lngStoreID]= cboStore")
MsgBox ": " & cboStore

Me.cboManager.R owSource = sManagerSource
Me.cboManager.R equery


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
4282
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 Agency Types, then the 2nd combo box displays a list of Organisations, depending upon the Agency Type Selected. The first combo box 'ctlType' (Unbound), Row Source: to field in 'AgencyReferralType'.
0
1826
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 for input to another operation. Originally, I had a drop-down box with the client name and the client id number and it worked fine, but it was for a demo and was quick-and-dirty. For the real app, there are over 1,700 client ids and the...
2
5599
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
2251
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: ------------------------ // Fill the datasets for the combo boxes daDepartment.Fill(dsDepartment.Departments);
7
12277
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 a combo box, to select an ad from the drop down list. I would like the Depts form to open with the Ad selected on the Main form displaying in the combo box, AND any information already added presented to the user. (I am thinking this latter...
5
3702
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 just choose the appropriate criterias from the combo boxes to get the results. I also want the query to run even if there is not a value in all the combo boxes ie., i want just all males with income level of over $100,000...Any insights or help...
1
3105
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 ultimately driven by the results of two combo boxes: 1st combo box on main form that filters desired results for 2d combo box on sub form Main form: no record source. Has an unbound combo box. name: frminput combo name: cboAccounts The row...
4
27805
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 dates for different company terminals. The form loads showing all records. In the form header I have a combo box named "CSCFilter" that is unbound, and uses the table/query option to list the 16 terminals in our company. The field I'm trying to...
2
1667
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 statement) of a combo box to display only records with the "Edited" field = "No". the button and the combo box are on the same form. the record is selected from the combo box. when i step through the code in debug mode, the combo box nicely...
0
9666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10412
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9986
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9021
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7529
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5422
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2909
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.