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 
OpenForm WHERE Syntax
Steve Johnston 
      
2 years ago
Hi all

I would like to utilize an AND operator within the WHERE clause in a VBA DoCmd.OpenForm statement. Is this possible and, if so, what is the recommended syntax? I've tried using a FILTER clause but that doesn't seem to be recognized.
Steve Johnston OP  @Reply  
      
2 years ago

Steve Johnston OP  @Reply  
      
2 years ago
I attached the code. I am receiving a "Run-time error '13" message. When I debug the error it seems to be providing the criteria I am expecting. "GroupStatus.Value" refers to a lookup table and I believe that is possibly the source of the error. When I debug it shows a text string even though it should be an integer (i.e. column 0). If my premise is correct, in this example the proper integer "value" should be 508. Any assistance would be greatly appreciated :)
John Davy  @Reply  
         
2 years ago
Hi Steve,
watch todays video that Rick provided. Even though it is about date, I think it will help you. What do you expect GroupStatus.value
to be? Are you comparing it to something?
John
Kevin Robertson  @Reply  
          
2 years ago
Here is the proper syntax.
The first example hard codes the SalesRepID.
The second example gets the SalesRepID from a Combo Box.

Example 1
    DoCmd.OpenForm "OrderF", , , "CustomerID=" & CustomerID & " And SalesRepID=2", acFormEdit

Example 2
    DoCmd.OpenForm "OrderF", , , "CustomerID=" & CustomerID & " And SalesRepID=" & cboSalesRep, acFormEdit
Steve Johnston OP  @Reply  
      
2 years ago
Kevin - thank you so much! That addressed my issue perfectly.
John - I will watch the video and thank you for the recommendation.
Have a great day everyone.
Kevin Robertson  @Reply  
          
2 years ago
You're welcome. Glad I could help.
Thomas Gonder  @Reply  
      
2 years ago
Another option to the WHERE parameter in DoCmd.OpenForm is to just set the Form's source for building/testing.
I then clear that field in the designer and do a SQL statement in VBA and stuff it into the:
frm.RecordSource = wSql
  frm.Filter = cZls: frm.OrderBy = cZls 'should be nothing, all in source
  frm.FilterOn = False: frm.OrderByOn = False
later in the Form_Load procedure.
This gives me a lot of flexibility in the Where (filter) and Sort part which I can change later in the VBA code if necessary. This is used a lot in Search forms, but I also allow the users to define the filter & sort that works best for their organization from a supporting table field.

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/1/2026 8:12:39 PM. PLT: 1s