?
Solved

MS Access VBA Syntax for Combo Box After Update Event

Posted on 2014-09-11
9
Medium Priority
?
1,199 Views
Last Modified: 2014-09-11
I need to populate a second combo box based on the item selected from the 1st combo box.

cboCategoryList is combo box 1.
cboFeatureList  is combo box 2.
The combo box value is numeric.  
Combo Box After Update

Private Sub cboCategoryList_AfterUpdate()
    Me.cboFeatureList.RowSource = "SELECT Feature.Fea_No, Feature.Fea_Name, Feature.Cat_No FROM Feature WHERE Feature.Cat_No = "
    Me.cboCategoryList.SelText " ORDER BY Feature.Fea_Name ; "

Me.cboCategoryList.SelText  Is this the value selected from cboCategoryList ?

How do I append the strings?

Me.cboFeatureList.RowSource = "bla sle9 " & " geoel  dakf" is this correct?

Thanks,


End Sub
0
Comment
Question by:Dovberman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
9 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40317943
if Cat_No is NUMBER datatype the syntax is

Me.cboFeatureList.RowSource = "SELECT Feature.Fea_No, Feature.Fea_Name, Feature.Cat_No FROM Feature WHERE Feature.Cat_No = " &  Me.cboCategoryList & " ORDER BY Feature.Fea_Name"


if Cat_No is TEXT data type the syntax is

Me.cboFeatureList.RowSource = "SELECT Feature.Fea_No, Feature.Fea_Name, Feature.Cat_No FROM Feature WHERE Feature.Cat_No = '" &  Me.cboCategoryList & "' ORDER BY Feature.Fea_Name"

the value of the cboCategoryList  is set to the Bound Column in the Rwosource of the combo box.
0
 

Author Comment

by:Dovberman
ID: 40317968
Thanks,

I get a syntax error.

Me.cboFeatureList.RowSource = "SELECT Feature.Fea_No, Feature.Fea_Name, "
    Feature.Cat_No FROM Feature WHERE Feature.Cat_No = " & Me.cboCategoryList & "
    ORDER BY Feature.Fea_Name"

What am I missing?
0
 

Author Comment

by:Dovberman
ID: 40317979
This SQL runs.

SELECT Feature.Fea_No, Feature.Fea_Name,
    Feature.Cat_No FROM Feature WHERE Feature.Cat_No = 1
    ORDER BY Feature.Fea_Name ;

-- I hard coded Me.cboCategoryList  as 1.
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

Author Comment

by:Dovberman
ID: 40317996
the combo boxes behave as expected if I do not append strings.

Entered as a single line of code.
Me.cboFeatureList.RowSource = "SELECT Fea_No, Fea_Name, Cat_No FROM Feature " & "WHERE Cat_No = " & Me.cboCategoryList & " ORDER BY Feature.Fea_Name"

What is happening?

I would like to make the statement more readable by using multiple lines.
0
 

Author Comment

by:Dovberman
ID: 40318014
Private Sub cmdGetSyntax_Click()
    Me.txtSyntax.Text = "abc" & " def"
    & "kyg" & " "
End Sub


Error: Expected line number, or end of statement

Private Sub cmdGetSyntax_Click()
    Me.txtSyntax.Text = "abc" & " def"   & "kyg"

End Sub

Compiled without error.

Any ideas?

I will try this on my MS access installation at home.

Thanks,
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 40318160
try this

Me.cboFeatureList.RowSource = "SELECT Fea_No, Fea_Name, Cat_No FROM Feature" _
    & " WHERE Cat_No = " & Me.cboCategoryList & " ORDER BY Feature.Fea_Name"
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40318162
or

Me.cboFeatureList.RowSource = "SELECT Fea_No, Fea_Name, Cat_No FROM Feature" _
     & " WHERE Cat_No = " & Me.cboCategoryList & " _
     & " ORDER BY Feature.Fea_Name"
0
 

Author Comment

by:Dovberman
ID: 40318273
You are right. I also forgot about the VBA line return character.

Thanks,
0
 

Author Closing Comment

by:Dovberman
ID: 40318274
Thank you.
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question