473,383 Members | 1,798 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,383 software developers and data experts.

Combobox selecting wrong value

18
On my main form I have a Product drop down. Once a product is select, the Module combo box is to be popluated with modules related to that product.

The combo box populates correctly, but if I click on any module, it automatically selects the first item in the box.

Example:

My Product is CA, the modules are Assessment, Capacity, Implementation, Planning, Evaluation, REports, Other.

If I select CA, then under module I select Implementation, the module combobox popluates with "assessment"

Here is my code for the Product on change event
Expand|Select|Wrap|Line Numbers
  1. Private Sub Product_Change()
  2. Dim t As String
  3.  
  4.     t = Me.Product.Value
  5.  
  6.     cboModule.SetFocus
  7.     cboModule.RowSource = "Select [product id], Module FROM Module where [product id] = " & t & ";"
  8.     Product.SetFocus
  9.  
  10. End Sub
Can anyone help me with this problem?

Thank you
Oct 13 '08 #1
8 2174
NeoPa
32,556 Expert Mod 16PB
You need to surround t with quotes (Line #7) :
Expand|Select|Wrap|Line Numbers
  1. "... = '" & t & "';"
Oct 13 '08 #2
NeoPa
32,556 Expert Mod 16PB
Unless I miss my guess, you also want to consider using the AfterUpdate event rather than the Change event.
Oct 13 '08 #3
lrw0831
18
Adding the quotes did not work. It caused it to not populate the module combobox.
Oct 13 '08 #4
NeoPa
32,556 Expert Mod 16PB
What's the value of t when this happens? It seems that something you're saying is not quite accurate.

Add a "MsgBox t" line before you set up the SQL and post in here the value displayed please.
Oct 13 '08 #5
lrw0831
18
I am new to Access and I'm not sure how to do this. Could you tell me what to add to the code?
Oct 13 '08 #6
NeoPa
32,556 Expert Mod 16PB
Of course. No problem.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Product_Change()
  2. Dim t As String
  3.  
  4.     t = Me.Product.Value
  5.     MsgBox t
  6.  
  7.     cboModule.SetFocus
  8.     cboModule.RowSource = "Select [product id], Module FROM Module where [product id] = " & t & ";"
  9.     Product.SetFocus
  10.  
  11. End Sub
The line I added is found at #5.

To get to where the code is go into Design mode of the form, Select the [Product] control, Hit Alt-Enter to view the proerties, Find the On Change property, Click on the elipsis button to the right of it when it is selected.

Now you are in the VBA Editor window. Code can be manipulated from here. Paste in this version over the top of your earlier version.
Oct 13 '08 #7
lrw0831
18
Thank you for your help. I was able to get this to work.
Oct 14 '08 #8
NeoPa
32,556 Expert Mod 16PB
Very pleased to hear it. Well done :)
Oct 14 '08 #9

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

Similar topics

0
by: Gamze | last post by:
Hi, In my vb.net windows application ,i have combobox which is populated by sqlserver database table.When i select value from combobox ,value saved in to other table of my database and i use to...
3
by: Ronny Sigo | last post by:
Hello all, On my form I have an unbound combobox based on a query displaying two rows. The rows are : 1) Zipcode (Leftmost (In the query this field is sorted ascending 2 City The...
14
by: Norm | last post by:
Hi, Each time the user selects an item from a combobox, I want that string to get appended to the values that were already selected. The result is that the combo is accumulating text each time...
8
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
5
by: Claudio Di Flumeri | last post by:
Hi all, Iive found this bug int the VB combobox and I'd like to know if there is a way to solve it... Put a combobox in a form, and fill it with these 3 items: - athens - berlin - chicago ...
7
by: Simon Verona | last post by:
I posted this in dotnet.languages.vb.controls but thought I'd post here as well.. I have a combobox that is bound to a dataview generated from a dataset. The dataset has a single table...
2
by: shumaker | last post by:
I have a combobox that is very much like the one found in the RSS project here: http://msdn.microsoft.com/vstudio/express/visualCSharp/learning/ My projectNameComboBox basically is filled with a...
3
by: Simon Tamman | last post by:
I've come across an interesting bug. I have workarounds but i'd like to know the root of the problem. I've stripped it down into a short file and hope someone might have an idea about what's going...
19
by: billa856 | last post by:
Hi, I have to use the table(PRODUCTION) already generated in MS Access in which all fields are of TEXT type.fields like (orderdate,palletno,customercode,itemno,pono,carto n,pcs,totalquantity)Now i...
1
by: beemomo | last post by:
hi everyone! i need to display all the data of a record in a form by selecting the value of combobox. for example when i select a Project_No display in combobox, the correspondence data of that...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.