473,785 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to set Row Source in Combo Box in VBA based on a variable?

I want to have a second combo box have its selection options based on a
selection made in a first combo box. The first one gathers data from a
table, and the second one should gather data from a related table depending
on the selections of the first. Using the wizard will give me a specific
field but will not have a WHERE clause. Is there some code to indicate that
the row source is built a variable in the sub set by the first combo box?
Nov 13 '05 #1
3 63590
> I want to have a second combo box have its selection options based on a
selection made in a first combo box. The first one gathers data from a
table, and the second one should gather data from a related table depending on the selections of the first. Using the wizard will give me a specific
field but will not have a WHERE clause. Is there some code to indicate that the row source is built a variable in the sub set by the first combo box?


Dim varValue

varValue=TextBo x1.Value or varValue=TextBo x1.Column(0)

TextBox2.RowSou rce="SELECT * FROM varTABLE WHERE v = " & varValue

--

Bye

Dariusz My¶liwiec

----------------------------------------------------------------------
E-mail: da************* **@darekmysliwi ec.biz
WWW: http://www.darekmysliwiec.biz/
-----------------------------------------------------------------------
Nov 13 '05 #2
Here's what I have so far:
Private Sub cboSelectGroup_ Change()

Dim groupSelection as Integer

Me("cboSelectCo urse").Enabled = False
' cboSelectCourse , used in this With statement, is the first name of the
first combo box

With Me("cboSelectGr oup")
.RowSource = "SELECT Groups.groupID, Groups.groupDes cription,
Groups.courseCo de " _
& "FROM Groups " _
& "WHERE (Groups.courseC ode = ' & me!cboSelectCou rse & ') " _
& "ORDER BY groupID"

.RowSourceType = "Table/Query"
.BoundColumn = 1
.ColumnCount = 3
.ColumnWidths = "0in;.05in;.05i n"
.ListRows = 8
End With

groupSelection = me("cboSelectCo urse")

End Sub

But the box still comes up blank.

"Gonty" <bl******@poczt a.onet.pl> wrote in message
news:cd******** *@news.onet.pl. ..
I want to have a second combo box have its selection options based on a
selection made in a first combo box. The first one gathers data from a
table, and the second one should gather data from a related table depending
on the selections of the first. Using the wizard will give me a specific field but will not have a WHERE clause. Is there some code to indicate

that
the row source is built a variable in the sub set by the first combo

box?
Dim varValue

varValue=TextBo x1.Value or varValue=TextBo x1.Column(0)

TextBox2.RowSou rce="SELECT * FROM varTABLE WHERE v = " & varValue

--

Bye

Dariusz My¶liwiec

----------------------------------------------------------------------
E-mail: da************* **@darekmysliwi ec.biz
WWW: http://www.darekmysliwiec.biz/
-----------------------------------------------------------------------

Nov 13 '05 #3
No wonder. What you intended to refer to a control is actually imbedded in
the text string, so the value isn't being substituted. It's a good idea to
check such strings that you build by using Debug.Print or a MsgBox to
validate that you got what you intended.

Replace:

& "WHERE (Groups.courseC ode = ' & me!cboSelectCou rse & ') " _

with

& "WHERE (Groups.courseC ode = '" & me!cboSelectCou rse & "') " _

and then verify the generated string before executing it, so you aren't
trying to work in the dark.

Larry Linson
Microsoft Access MVP
"Richard Hollenbeck" <ri************ ****@verizon.ne t> wrote in message
news:ti******** ***********@nwr ddc02.gnilink.n et...
Here's what I have so far:
Private Sub cboSelectGroup_ Change()

Dim groupSelection as Integer

Me("cboSelectCo urse").Enabled = False
' cboSelectCourse , used in this With statement, is the first name of the first combo box

With Me("cboSelectGr oup")
.RowSource = "SELECT Groups.groupID, Groups.groupDes cription,
Groups.courseCo de " _
& "FROM Groups " _
& "WHERE (Groups.courseC ode = ' & me!cboSelectCou rse & ') " _
& "ORDER BY groupID"

.RowSourceType = "Table/Query"
.BoundColumn = 1
.ColumnCount = 3
.ColumnWidths = "0in;.05in;.05i n"
.ListRows = 8
End With

groupSelection = me("cboSelectCo urse")

End Sub

But the box still comes up blank.

"Gonty" <bl******@poczt a.onet.pl> wrote in message
news:cd******** *@news.onet.pl. ..
I want to have a second combo box have its selection options based on a selection made in a first combo box. The first one gathers data from a table, and the second one should gather data from a related table

depending
on the selections of the first. Using the wizard will give me a specific field but will not have a WHERE clause. Is there some code to
indicate that
the row source is built a variable in the sub set by the first combo

box?

Dim varValue

varValue=TextBo x1.Value or varValue=TextBo x1.Column(0)

TextBox2.RowSou rce="SELECT * FROM varTABLE WHERE v = " & varValue

--

Bye

Dariusz My¶liwiec

----------------------------------------------------------------------
E-mail: da************* **@darekmysliwi ec.biz
WWW: http://www.darekmysliwiec.biz/
-----------------------------------------------------------------------


Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
8899
by: Marnie Parker | last post by:
I am adding a drop down comb box to an existing database I wrote about a year ago. This combo box list names where the user can select which record to go to. Sigh. Last, First Name and a hidden key field. I've got everything working, and have it on different forms. Created a routine to set it to SELECT the right fields for the right table for the right forms. I also have it successfully ordering by.
3
8210
by: Bob Alston | last post by:
I am using a combo box to select the key to records and then go to the selected record on my form. Works well. However, the list, which contains people names, is rather long. What I would like to do is to allow entry of one or more letters of the beginning of the last name, like "j" for someone named Johnson (or Johnston) , where the list in the combo box will only show names equivalent to a "like {j*}" clause. So far it appears...
0
2929
by: Jeremy Wallace | last post by:
Folks, Here's a write-up I did for our developer wiki. I don't know if the whole rest of the world has already figured out how to do this, but I hadn't ever seen it implemented, and had spent a lot of time trying to figure it out, over the years. It finally dawned on me a couple of weeks ago how to do this. A couple of notes: 1) This is written for a different audience than CDMA; it's written for
2
2099
by: Tony A. | last post by:
The application I'm working on has three tables State, Customer, Orders. In the first combo box the State is selected. Based on the State selected the second combo box will be populated with the Customers in that state. Based on the Customer selected a datagrid will be populated with the customer's orders. I setup the query for the secont combo box as follows: Select CustName From tblCustomer Where State = @cboState
0
1430
by: Newbie in ChiTown | last post by:
User selects an item from (Combo box1). A value is passed to an unbound Combo box 2. I am trying to populate Combo box 2 (row source) based on the value passed from DAO recordset. Private Sub cboEmployeeNames_AfterUpdate() intEmpID = Me!cboEmployeeNames.Value Call PopulateEmployeesComboBox(Me) Function PopulateEmployeesComboBox(objForm As Form)
3
3784
by: hary08 | last post by:
im doing a database for Hospital Admission, I have a log in form which prompt user for a password. The source of log in is to look for the values in my Table tblEmployees and match user name and password entered.My case now is I have Audit Trail Module which keeps records of modifications and current user, I wanted my audit trail to log the current user based on who has log from based on my Log in Form.please help ty HERES THE CODE FOR ON...
4
3317
by: robtyketto | last post by:
I have generated combo boxes based on contents of other combos and am newbie who slowly learning vba code. Heres an example of vba code use to update one combo box from another Me.comboArea.RowSource = "Select Area.Area_ID, Area.Area, Facility.Facility " & _ "FROM Facility INNER JOIN Area ON Facility.Facility_ID = Area.Facility_ID " & _ "WHERE Area.Facility_ID = " & Me.combofacility.Value & ";" For the...
1
2194
by: keri | last post by:
I would like to have a combo box on a form that shows the results of a query, however the query is variable and i am unsure how to do this. I have NO knowledge of code so very basc instructions would be appreciated! I have a table "appointments" which contains an "appointment date" field. I have a form "planning" (based on another table) with a field for "date to plan". I would like a combo box to show any "appointments" already made...
1
1705
by: andyb7901 | last post by:
Hey, I have a combo box based on a table. It has two columns; The key which is hidden and the name of a location. On the form there is a subform which has a number of fields for equipment. This is based on another table. However, the tables are linked via a relationship. What I would like is when I select a locaton from the combo it changes the fields in the subform to match the location. Im not sure how to embed the query in my subform or...
1
10097
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9957
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
8983
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
7505
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
6742
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
5386
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...
0
5518
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
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
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.