Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Importance of Quotes in Code
Carlos Espinosa 
    
6 years ago
Hello Richard,

When the WHERE clause is inserted in the following subroutine, it desn't display any records on the listbox (LevelList). It does bring the correct value form CategoryCombo, as per MsgBox.

Private Sub CategoryCombo_AfterUpdate()
    Dim SQL As String
    
    LevelList.RowSource = "SELECT IdProduct, Date, Category, Level, Class " & _
                          "FROM ProgressQ WHERE Category = " & CategoryCombo & " " & _
                          "ORDER BY Category, Level, Class;"

    SQL = "WHERE Category = " & " " & CategoryCombo
    MsgBox SQL

End Sub

Any ideas?
Richard Rost  @Reply  
          
6 years ago
Does it work if you switch the data source from a query to a table?
Alex Hedley  @Reply  
           
6 years ago
What data type is Category?
Richard Rost  @Reply  
          
6 years ago
Good catch, Alex. I didn't even think about that because I'm so used to Combo Boxes always having IDs in them, but if your CategoryCombo has TEXT as the bound column, remember you need to enclose it in quotes.
Carlos Espinosa OP  @Reply  
    
6 years ago
Category is Short Text.
So, I should set the bound column on the Combo to CategoryID, then.
As a matter of course I think that's best.
I'll do both and let you know.

Thank you both, very much.
Richard Rost  @Reply  
          
6 years ago
Yep. IDs are best. If you do use text, you need to say:

SQL = "WHERE Category = '" & CategoryCombo & "'"

Unless your Category might have an ' in it, in which case:

SQL = "WHERE Category = """ & CategoryCombo & """"

Quotes can be tricky. I didn't used to mind too much about whether to do the ' or the "" until I started working with SQL Server which is much more picky. And I started dating a girl named D'Angelo and realized my Customer database might have a problem with her name in places. LOL
Carlos Espinosa OP  @Reply  
    
6 years ago
So why is it then, that MsgBox SQL returns a number, ie Category = 3.
Richard Rost  @Reply  
          
6 years ago
You could be storing a number in a text field. What are the columns for your combo box? Let me see the RowSource property.
Carlos Espinosa OP  @Reply  
    
6 years ago
1- Changed to IdCategory and it worked like a charm.
2- Tried the quotes, and not so much. I'm just not fluent in quotes.

3- Row source, this is the Sub that I just changed to, an worked.

If IsNull(CategoryCombo) Then
        WhereStr = " "
    Else
        WhereStr = "Where IdCategory = " & CategoryCombo & " "

    End If
    
    NivelLista.RowSource = "SELECT IdProduct, IdCategory, Date, Category, Level, Class " & _
                           "FROM ProgressQ " & _
                           WhereStr & _
                           "ORDER BY Category, Level, Class;"

Before I had, Category instead of IdCategory, in WhereStr on the Else part.
On RowSource, IdCategory wasn't there.
When IdCategory was added, also changed tweaked the property sheet of the ListBox to account for the new column.

Richard Rost  @Reply  
          
6 years ago
Yeah your best bet is to use the ID
Carlos Espinosa OP  @Reply  
    
6 years ago
It's good to know that the culprit was the field type.

Thank you Alex and Richard.
BTW This comes up in SQL 2 Class3, were Category data type is number.
As usual, my bad.

Richard Rost  @Reply  
          
6 years ago
Hey - don't worry about it. That's what you're here for: to learn! You will remember this now even more because you made that mistake. That's what I'm here for: to help you learn. Never be embarrassed or afraid to ask a question.
Carlos Espinosa OP  @Reply  
    
6 years ago
Ooooohhhh I see plenty of embarrassment to come in my Access near future, Seor Richard.

My confidence is way up, now that I know that my lap top is fine and Access is installed properly.
After a while those two start creeping up the thought process and keep me away form paying attention the real culprits,
Quotes and data types.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/7/2026 5:01:31 AM. PLT: 1s