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

Cascading ComboBoxes to a TextBox - Code Tweak Needed

Walt in Decatur
I have implemented successfully a single-cascade ComboBox combination on a form in my database (using an AfterUpdate event code). I have also successfully implemented a ComboBox + TextBox combination, whereby the TextBox shows contents of another column from the query for the ComboBox.

It's when I try to link these two up together when the problem comes up. I've been trying to find a solution to this coding problem in a practice unbound form.

ComboBox1 is called Field1, it drives...
ComboBox2, which is called Field2. This has 2 Columns, the second one hidden
TextBox1, which is called Field3

Here is the code I'm using:

Private Sub Field1_AfterUpdate()
Me.Field2.RowSource = "SELECT Field_2 FROM" & _
" tbl_test WHERE Field_1 = '" & Me.Field1.Text & _
"' ORDER BY Field_2"
Me.Field2.Value = ""
Me.Field1.Requery
End Sub

When I first switch from Design to Form view, the TextBox and ComboBox2 properly display their contents. However, as soon as I actually use ComboBox1, the ComboBox2 filtering works, but the second column (containing what should be displayed in the TextBox goes blank, and so does the TextBox

Any suggestions for fixing the code?
Jul 17 '08 #1
6 2897
Stewart Ross
2,545 Expert Mod 2GB
Hi. A far simpler approach is to refer to the column of your combo box directly as the control source of your textbox - no coding required.

If you wanted to refer to the third column of your combo, set the control source of the textbox to

=[your combo name].column(2)

(Columns are numbered from 0.)

In the rowsource query of the combo you can add additional columns that are not displayed to the user when the combo is selected (by setting the column width for those columns to 0). You can then use these in other textboxes or in code on the after update event for instance as quick lookups. I use this type of lookup a lot to display related data for users without using the Dlookup function.

-Stewart
Jul 18 '08 #2
Stewart:

Thank you for replying. Indeed, that's the way the TextBox is set up. And it works fine, until the VBA for ComboBox1 is run. Then the fields for column which I want to appear in the TextBox go "blank". Since the TextBox is unbound (I just need that info for performing some calculations on the form), I don't know whether the correct info is actually being sent to it.

In short, there is something missing in the VBA that will not make that column info disappear.

Walter

Hi. A far simpler approach is to refer to the column of your combo box directly as the control source of your textbox - no coding required.

If you wanted to refer to the third column of your combo, set the control source of the textbox to

=[your combo name].column(2)

(Columns are numbered from 0.)

t
Jul 18 '08 #3
missinglinq
3,532 Expert 2GB
Are you. perchance, running version 2003 with the SP3 service pack installed? If so, try installing the hotfix at this Microsoft link:

http://support.microsoft.com/kb/945674

Welcome to Bytes!

Linq ;0)>
Jul 18 '08 #4
Thanks for the tip. The problem sounded like what I have, but...

I'm actually working in Access 2007 and the problem persists after I've saved the database in the new 2007 format. So I'm still stumped.

Are you. perchance, running version 2003 with the SP3 service pack installed? If so, try installing the hotfix at this Microsoft link:

http://support.microsoft.com/kb/945674

Welcome to Bytes!

Linq ;0)>
Jul 18 '08 #5
Stewart Ross
2,545 Expert Mod 2GB
Hi again Walt. From your first post your row source code, run on after-update of your other combo, selects but one field for your field 2 combo (reproduced again below - see SELECT in line 2). When you run this code the second column is bound to be blank as there is data only for column 0, the default column, and no other.

Code from post 1
Expand|Select|Wrap|Line Numbers
  1. Private Sub Field1_AfterUpdate()
  2. Me.Field2.RowSource = "SELECT Field_2 FROM" & _ '<< this selects just one field
  3. " tbl_test WHERE Field_1 = '" & Me.Field1.Text & _
  4. "' ORDER BY Field_2"
  5. Me.Field2.Value = ""
  6. Me.Field1.Requery
  7. End Sub
If your combo has two columns, one hidden, you surely have to select two fields for your revised rowsource??

-Stewart
Jul 19 '08 #6
Stewart:

Yes this was a problem. Since I don't have any formal training in SQL or Access, even simple things like this can stymie me. Thank goodness for all of you patient helpers!

Walter

Hi again Walt. From your first post your row source code, run on after-update of your other combo, selects but one field for your field 2 combo (reproduced again below - see SELECT in line 2). When you run this code the second column is bound to be blank as there is data only for column 0, the default column, and no other.


-Stewart
Jul 24 '08 #7

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

Similar topics

0
by: cognoscento | last post by:
I'm currently putting together a database for my work (not an expert by any stretch, so muddling through as best as I can... you know the story...) and I could use some advice and hand-holding ...
4
by: pmcguire | last post by:
I have 2 bound ComboBoxes. I want the datasource of the second to be limited by the selection made in the first. I can do this by responding to the SelectionIndexChanged event on the first, but...
6
by: visionstate | last post by:
Hi there, I am building a database that requires cascading lists on a form. I currently have (I may be adding more later) 3 combo boxes on my form - Department, Surname and Forename. The user...
19
by: Amanduh | last post by:
Hi again, brilliant developers. I'm having serious issues with cascading comboboxes. I had it working perfectly before, but then was asked to add an additional variable and everything went haywire...
4
klarae99
by: klarae99 | last post by:
Hello, I am working on an Access 2003 Database. The tables that pertain to this issue are tblOrg, tblState, tblCity, and tblZip. I have posted the table structure with only the pertinant fields...
12
by: azalea45 | last post by:
Hi all I am a newbie when it comes to access. My company requires that all Databases run on the company SQL back-end as a result i have a Access project that connects to the server. I have two...
2
by: greenMark | last post by:
Hi All, I'm relatively new to ASP.NET and Visual Web Developer 2008. I'm using a Master page with one content place holder. There is a Cascading Style Sheet file which is being refered by the...
16
by: AFSSkier | last post by:
I have several cascading ComboBoxes & would like to close Cbo2 & open Cbo1 when there is an error. These CboBoxes are on an Excel spreadsheet, not a UserForm. I have the following code, if the...
16
by: Tarheel | last post by:
...You're fast! I appreciate that. Thanks! I look forward to your explanation. One last problem I have on my form is getting all of my comboboxes to update each other. I know how to update...
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: 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...
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
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,...
0
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...
0
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...

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.