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

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 63487
> 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=TextBox1.Value or varValue=TextBox1.Column(0)

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

--

Bye

Dariusz Myśliwiec

----------------------------------------------------------------------
E-mail: da***************@darekmysliwiec.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("cboSelectCourse").Enabled = False
' cboSelectCourse, used in this With statement, is the first name of the
first combo box

With Me("cboSelectGroup")
.RowSource = "SELECT Groups.groupID, Groups.groupDescription,
Groups.courseCode " _
& "FROM Groups " _
& "WHERE (Groups.courseCode = ' & me!cboSelectCourse & ') " _
& "ORDER BY groupID"

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

groupSelection = me("cboSelectCourse")

End Sub

But the box still comes up blank.

"Gonty" <bl******@poczta.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=TextBox1.Value or varValue=TextBox1.Column(0)

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

--

Bye

Dariusz Myśliwiec

----------------------------------------------------------------------
E-mail: da***************@darekmysliwiec.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.courseCode = ' & me!cboSelectCourse & ') " _

with

& "WHERE (Groups.courseCode = '" & me!cboSelectCourse & "') " _

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.net> wrote in message
news:ti*******************@nwrddc02.gnilink.net...
Here's what I have so far:
Private Sub cboSelectGroup_Change()

Dim groupSelection as Integer

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

With Me("cboSelectGroup")
.RowSource = "SELECT Groups.groupID, Groups.groupDescription,
Groups.courseCode " _
& "FROM Groups " _
& "WHERE (Groups.courseCode = ' & me!cboSelectCourse & ') " _
& "ORDER BY groupID"

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

groupSelection = me("cboSelectCourse")

End Sub

But the box still comes up blank.

"Gonty" <bl******@poczta.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=TextBox1.Value or varValue=TextBox1.Column(0)

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

--

Bye

Dariusz Myśliwiec

----------------------------------------------------------------------
E-mail: da***************@darekmysliwiec.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
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...
3
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...
0
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...
2
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...
0
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...
3
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...
4
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 ...
1
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...
1
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...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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.