473,761 Members | 8,933 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cascading ComboBoxes to a TextBox - Code Tweak Needed

Walt in Decatur
20 New Member
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_AfterUpd ate()
Me.Field2.RowSo urce = "SELECT Field_2 FROM" & _
" tbl_test WHERE Field_1 = '" & Me.Field1.Text & _
"' ORDER BY Field_2"
Me.Field2.Value = ""
Me.Field1.Reque ry
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 2919
Stewart Ross
2,545 Recognized Expert Moderator Specialist
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
Walt in Decatur
20 New Member
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 Recognized Expert Specialist
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
Walt in Decatur
20 New Member
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 Recognized Expert Moderator Specialist
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
Walt in Decatur
20 New Member
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
2078
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 I've got a subform with a series of cascading combo boxes (thanks to the Access tutorials on fontstuff.com) that let the user assign categories to items, in this case photos. This is being done to help constrain user selections and keep the...
4
7825
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 this results in the BindingContext's Current.Row.Rowstate becoming 'Modified' whenever the BindingContext position changes. What is the RIGHT way to go about this? Thanks, -- Pat
6
2086
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 chooses the department they want and then the corresponding surnames from that department can be chosen from the Surname box and then the Forename depending on which Surname they chose. I then have a command button which produces the results of the...
19
2325
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 (surely due to my incompetence). I've printed out Rabbit's tutorial and read it many times, but like others, I feel I need a more elementary approach. Please let me explain: I'm creating a database for entering information for research studies. ...
4
3496
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 below. tblOrg OrgID, AutoNumber, PK ZipID, Number, FK tblState StateID, AutoNumber, PK
12
1727
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 tables, table 1 called tblProjectDetails, table 2 called tblLearners The fields in tblProjectDetails are ProjectPK numeric (Its also the Primary Key)] Name char (50) Description char (50) There are other field but they dont play a role in the...
2
9633
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 master page file as follws "<link href="myStyleSheet.css" rel="Stylesheet" type="text/css"/>" Part of the Style sheet as follows: .textbox
16
10614
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 Dropdown is opened it requeries Cbo2 to ListIndex = 0. But I also want it to close (unselect, undrop list) Cbo2 & open (select, dropdown) Cbo1 on MsgBox error. This insures the user selects property of Cbo1 first. Private Sub...
16
2394
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 them as a cascade (i.e. Region updates Country which updates State which updates City) but I would like them to be interdependent (i.e. if I select a City, I want the Region, Country, and State comboboxes to populate with the corresponding data. ...
0
9376
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
9988
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
9811
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...
1
7358
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
6640
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3911
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 we have to send another system
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
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.