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 Developer Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Multiple Criteria Inside of for Next Loop
Gary Becker 
     
4 months ago
I'm populating a combo box with the table names in the database using a For-Next loop. I want to filter the names it returns with the tables that start with APM, GLM, CMT, and JCM for examples. It works with the following code, but I just have two of the criteria and I was looking for a cleaner way to add more instead of continuing to use the OR keyword.
Gary Becker OP  @Reply  
     
4 months ago

Alex Hedley  @Reply  
           
4 months ago
Could just change it to a Query
Alex Hedley  @Reply  
           
4 months ago
SELECT MSysObjects.Name, MSysObjects.Type
FROM MSysObjects
WHERE (((MSysObjects.Name) Not Like "MSYS*") AND ((MSysObjects.Type) In (?)))

Can't remember which number the ? should be
Kevin Robertson  @Reply  
          
4 months ago
You could use an Array.

Private Sub PopulateCombo()

    Dim obj As AccessObject, dbs As Object
    Dim tableArray As Variant, pattern As Variant

    Set dbs = Application.CurrentData

    tableArray = Array("PRT*", "JCT*", "APM*", "GLM*")

    For Each obj In dbs.AllTables
        For Each pattern In tableArray
            If obj.Name Like pattern Then
                comboTable.AddItem obj.Name
                Exit For
            End If
        Next
    Next
    
End Sub
Gary Becker OP  @Reply  
     
4 months ago
This worked great. Now I'm using that code to scroll through LINKED tables and using CurrentDB.execute to run some MAKE TABLE SQL in another database. But I get the Table {name} already exists error 3010. I've turned the warnings off at the database level in the Options-Client Settings-Confim Action Queries. And I'm using the Setwarnings False code. If I run it from a saved Query, it works fine. But trying to use MakeTable SQL with VBA doesn't. See my code below.
Gary Becker OP  @Reply  
     
4 months ago

Gary Becker OP  @Reply  
     
4 months ago
I failed to say: The code runs fine when there are not tables in the destination database. I'm wanting to overwrite them because I want to automate this whole process with the Task Scheduler in off hours.
Gary Becker OP  @Reply  
     
4 months ago
Okay, I changed the CurrentDb.Execute to DoCmd.RunSQL and it works. Great. Why??

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developer 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/6/2026 4:38:17 AM. PLT: 0s