Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Help   Contact   Merch   Join   Order   Logon   Forums   
 
Back to List Box Filter    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
MultiSelect Criteria for a
Jeffrey Kraft 
      
2 years ago
I modified Richards CustomerT State field from being a Short Text to a Number. Reason being I thought I'd push myself and have a Combo box on the CustomerF.  Everything in Richards code works fine until it hits this line.

    Forms!CustomerFrm.RecordSource = S  
  Error message is Run-time error '3464': and the dreaded Data Type mismatch in criteria expression.  I know that it's expecting a numeric value but S is a string.  How do I fix this without pulling out the rest of my hair.
Adam Schwanz  @Reply  
            
2 years ago
With something like state I would just leave it as a short text and store the actual value. There aren't very many and you aren't going to be adding more or changing them (unless you go worldwide and store them in that combo). One less relationship to deal with, but it's fine if you do that.

There is no CustomerFrm in the downloadable database so could you share the whole code section related to that sub you have so we know which part is erroring?
Sami Shamma  @Reply  
             
2 years ago
Adam is correct (like usual). Without looking at the code, I guess "S" is defined as a String and now you are assigning a Number to it.
Jeffrey Kraft OP  @Reply  
      
2 years ago
It didn't have to be States.  It could have been Desserts, Starships, Car Models, Candy, or something where you likely wouldn't use a String but rather a number.  This video is main reason I finally caved in and joined.  Other videos had almost tipped me into joining.  And I have learned a lot so far, and yes I'm going to rewatch the 4 hour beginner course (which I watched earlier on YouTube).  But I'm back again where I started because I love banging my head on a brick wall :).

My original coding was closer to what somebody at Stackoverflow.com did, and it snaps/dies/crashed at the same spot.  I like Richards approach as the code looks cleaner and .

I can now see why some coders don't like Multi-Select List Boxes with a passion, and saw some code that worked with numeric values but a.) I can't find that code sample at this time and b.) when I saw the code previously I couldn't wrap my head around it.
Kevin Robertson  @Reply  
           
2 years ago
What is stored in S?
Jeffrey Kraft OP  @Reply  
      
2 years ago
In Richards code S is a String

It's the S = "SELECT * FROM CustomerT Where StateID IN (" & S & ")"  

I Think I found another way, It's using a Form's filter rather than a Query.... but I really really really wanted to use a Query instead.
Jeffrey Kraft OP  @Reply  
      
2 years ago
I found a way to do it.

On my form with the list box the VBA is

Private Sub CustomerListBtn_Click()
    On Error GoTo Err_cmdFilter_Click
    Dim i As Variant
    Dim StrIN As Variant
    
    StrIN = ""
    For Each i In StateList.ItemsSelected
        StrIN = StrIN & StateList.ItemData(i) & ","
    Next i
    StrIN = Left(StrIN, Len(StrIN) - 1) ' remove trailing comma.
   ' Set the Filter Text that will be called with the CustomerListQ2Frm Opens
    Me.MyFilterTxtBx = "StateID IN(" & StrIN & ")"
  
    DoCmd.OpenForm "CustomerListQ2Frm"

Exit_cmdFilter_Click:
    Exit Sub

Err_cmdFilter_Click:
Select Case Err.Number
    Case 5
        MsgBox "Please select 1 or more items from the listbox", vbOKOnly
    Case Else
        MsgBox Err.Number & "-" & Err.Description
End Select
Resume Exit_cmdFilter_Click

End Sub

The other form opens the Form Load event checks to see if that form is open and if it is, it borrows the location and sets the filter condition and turns the filter.  If it's not open it doesn't matter.
  
Private Sub Form_Load()
    Dim StrIN As Variant
    'Check to See if ListBoxFrm is loaded
    If CurrentProject.AllForms("ListBoxFrm").IsLoaded Then
        MsgBox ("The Form ListBoxFrm is Loaded")
        StrIN = Forms!ListBoxFrm!MyFilterTxtBx
        Me.Filter = StrIN
        Me.FilterOn = True
    End If

End Sub

This thread is now CLOSED. If you wish to comment, start a NEW discussion in List Box Filter.
 

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: 8/17/2026 6:07:28 PM. PLT: 1s