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 
SQL Date Search
Jon Capps 
       
4 years ago
I am stuck, I have been trying to figure out what is wrong with my syntax what am I doing wrong with the SQL  


This does not work
-----------
Dim sqlstring As String
sqlstring = "SELECT * " & _
"FROM AfterDavidInvoicedatefollowup " & _
"WHERE DateInvSentAdj = #" & "02/27/2022" & "#"
DoCmd.OpenForm "AfterDavidInvoicedatefollowup", , , _
DateInvSentAdj & sqlstring

--------------

This does work
DoCmd.OpenForm "AfterDavidInvoicedatefollowup", , , _
"DateInvSentAdj = #" & "2/27/2022" & "#"


-------------------

and This does work

DoCmd.OpenForm "AfterDavidInvoicedatefollowup", , , _
"DateInvSentAdj = #" & Nz(Forms!UpdateClaimAfterDavidisFinished!DateUpdate, "2/20/2012") & "#"

Jon Capps OP  @Reply  
       
4 years ago

Scott Axton  @Reply  
        
4 years ago
Jon  
Just let Access show you.  Create a query in the query designer and get it working.  Then switch the query window over to SQL view where you can then copy and paste the SQL to compare Access' SQL and yours.
Very valuable method for learning the SQL Language.
Kevin Robertson  @Reply  
          
4 years ago
Why do you need the SQL string to open your form? The way you have it written the entire Select statement is going into the Where Condition of the OpenForm Method. Unless there is a particular reason for the SQL I would use the middle option.

Also, you don't need the quotes around the date.
DoCmd.OpenForm "AfterDavidInvoicedatefollowup", , , "DateInvSentAdj = #2/27/2022#"
Jon Capps OP  @Reply  
       
4 years ago
got a follow up question, I went with the  code

DoCmd.OpenForm "AfterDavidInvoicedatefollowup", , , _
"DateInvSentAdj = #" & Nz(Forms!UpdateClaimAfterDavidisFinished!DateUpdate, "") & "#"


This is a continuous form, how could I make it sort on last name when the form opens. Then after I have the form open is it possible, with VBA to sort on any column, just like you could if you open the query?  I bet there is a video and I am not using the right search criteria.
Alex Hedley  @Reply  
           
4 years ago
Jon Capps OP  @Reply  
       
4 years ago
just had remember seeing in a video somewhere where I could do this:
Private Sub LastNameSort_Click()
Dim SQL As String
SQL = "SELECT * From AfterDavidInvoicedatefollowup ORDER BY ClmLast DESC;"
DoCmd.OpenForm "AfterDavidInvoicedatefollowup", , , SQL
'rename LastNameSort label to Last Z-A
'click again rename LastNameSort label to  Last A-Z
End Sub


I am searching though videos, any hints please
Jon Capps OP  @Reply  
       
4 years ago
thanx Alex

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/6/2026 1:55:34 AM. PLT: 0s