Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Search Form 2.0    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Query By Date Not Working
J David Bacon 
    
3 years ago
I have Bank Register Query which contains 75 records. My Register Form has two Unbound Text Fields used for filtering the Query for specific dates.  The Query Criteria is as follows:
Is Null Or Between [Forms]![BankRegisterF]![dtmDateFromSearch] And [Forms]![BankRegisterF]![dtmDateToSearch].

When I run the Query from the form using Date Ranges like 01/04/2021 to 01/04/2021 I get a blank screen.  If I remove the Query Criteria and enter the Criteria manually, I get the same results...no records being displayed.

There are 10 records which meet the specification in the Criteria.

I have Compacted the Database several times...same results.

Access is running on Windows 11 machine with MS Office 365

Any Help would be greatly appreciated.
Scott Axton  @Reply  
        
3 years ago
The biggest issue I see is if you are storing time in the Date/Time field as well.  Is that the case in your case?

If not how are you entering the date in your query?
Please post a screen shot of the query so we can take a look at what you are doing.
J David Bacon OP  @Reply  
    
3 years ago
Dates are stored in both the table and included in the query.  The Date is stored in Short Date format.
Kevin Yip  @Reply  
     
3 years ago
You need to requery the query after you entered the dates.  This needs to be done in the AfterUpdate events of the two textboxes.

You can also use the Filter and FilterOn properties of your form to specify the date criteria instead of having to put the criteria in the query itself.
J David Bacon OP  @Reply  
    
3 years ago
Perhaps some clarification is needed. I am using the DMax and DMin in the Load Sub to set the Default Date Search Fields and the last line in the Load Sub is Me.Requery. When the form is loaded, the Date Search Fields on the Form are Blank and no data is displayed.  If I remove the Date Search from the Query, the Form is Loaded Correctly with the correct DMax/DMin Date Values.

If I then change Values in the Date Search Fields and Requery the Form using the After Update Event, the Form do not Requery...that is nothing changes.

I have two (2) Search Fields on the Form and they work correctly.  It is only the Date Search Fields that are not working correctly,

Form Code below:
Private Sub dtmDateToSearch_AfterUpdate()
    '
    '       Set Date Range Max
    '
    Me.Requery
    
End Sub

Private Sub dtmDateToSearch_AfterUpdate()
    '
    '       Set Date Range Max
    '
    Me.Requery
    
End Sub

J David Bacon OP  @Reply  
    
3 years ago
PS. I just realized when I remove the Date Search from the Query and enter Dates in the Date Search Field on the Form...DA it would not work...too much coffee or not enough...not sure which.
Kevin Yip  @Reply  
     
3 years ago
Right after Me.Requery, add the line:

     MsgBox Me.Recordsource

If your form's recordsource is an SQL statement, the message box will show you the SQL, so you can see if it was constructed properly.  This is a common technique to debug things like this.  You can also add a breakpoint in the VBA editor, so that the code will pause at the line that has the breakpoint, allowing you to test the values of variables and properties, such as recordsource.
J David Bacon OP  @Reply  
    
3 years ago
My recordsource is not an SQL Statement.  I put the Msgbox Me.Recordsource after the Me.Requery and the message displayed the name of the Query for the form. Note: when I remove the default DMax/DMin statements and have not default dates, the Enter Paremeter Box is displayed.  If I enter Dates in this box, nothing happens the form is still blank.
Kevin Yip  @Reply  
     
3 years ago
Does the parameter prompt say "[Forms]![BankRegisterF]..." or something like it?  If the form reference appears as a parameter, that means the form reference is incorrect and can't evaluate, thus prompting you for a value.  If you enter dates into the parameters (dates that you know would give results) and still see no results, that means the query has another problem somewhere else in it.  So you need check the SQL of the query again.  You may try:

     MsgBox CurrentDb.QueryDefs("Your query name here").SQL

to see the SQL statement in the msgbox.  See if anything is amiss there.  If you can't tell, then you need to open your query in the navigation pane *while your form is open*.  Go into design view and SQL view and see if anything is amiss.  If you still can't tell, post the query's SQL here.
J David Bacon OP  @Reply  
    
3 years ago
Below is the SQL for the CYTransactionQ Query:

SELECT CYTransactionT.TransactionID, CYTransactionT.RegisterID, CYTransactionT.TransactionNumber, CYTransactionT.TransactionDate, CYTransactionT.TransactionType, CYTransactionT.CheckNumber, CYTransactionT.VendorID, VendorNameT.VendorName, CYTransactionT.AccountID, ChartofAccountT.COAGroup, ChartofAccountT.COACategory, ChartofAccountT.COASubcategory, ChartofAccountT.COASegment, CYTransactionT.Debit, CYTransactionT.Credit, CYTransactionT.Note, CYTransactionT.SplitTransaction, CYTransactionT.Reconciled, CYTransactionT.TransactionPosted, DSum("Credit","CYTransactionT","TransactionID<=" & [TransactionID] & "AND RegisterID=" & [RegisterID])-DSum("Debit","CYTransactionT","TransactionID<=" & [TransactionID] & "AND RegisterID=" & [RegisterID]) AS BankBal
FROM (VendorNameT INNER JOIN CYTransactionT ON VendorNameT.VendorID = CYTransactionT.VendorID) INNER JOIN ChartofAccountT ON CYTransactionT.AccountID = ChartofAccountT.COAID
WHERE (((CYTransactionT.TransactionDate) Is Null Or (CYTransactionT.TransactionDate) Between [Forms]![BankRegisterF]![dtmDateFromSearch] And [Forms]![BankRegisterF]![dtmDateToSearch])) OR (((VendorNameT.VendorName) Like "*" & [Forms]![BankRegisterF]![txtVendorNameSearch] & "*" Or (VendorNameT.VendorName) Is Null) AND ((ChartofAccountT.COACategory) Like "*" & [Forms]![BankRegisterF]![txtCOACategorySearch] & "*" Or (ChartofAccountT.COACategory) Is Null))
ORDER BY CYTransactionT.TransactionID, CYTransactionT.TransactionDate;

Note: I change the WHERE From AND to OR for the date search criterias.  This seems to work correctly.  Howeve, when I enter in a date into either the dtmDateFromSearch of dtmDateToSearch on the Form the AfterUpdate does not Requery the Form.

Hope this helps.
Kevin Yip  @Reply  
     
3 years ago
When you say "does not requery the form," do you mean (a) the  form's content doesn't change after requery, (b) the form becomes blank with no records after requery, or (c) the form is requeried and shows records, but they are not the records you expected?  You need to show me the rest of your VBA code in the AfterUpdate event.  We need to see what happens to the line Me.Requery: whether it was somehow skipped, or executed incorrectly.
J David Bacon OP  @Reply  
    
3 years ago
Below are the various Subroutines I am using:

Private Sub Form_Load()
    '
    '       Initialize Form
    '
    fileLocn
    regID = Forms!BankingF!cbxBankAccount
    picHelp.Picture = pngLocn & "Help.png"
    bankCat = Trim(DLookup("COACategory", "BankAccountT", Forms!BankingF!cbxBankAccount))
    bankSubCat = Trim(DLookup("COASubCategory", "BankAccountT", Forms!BankingF!cbxBankAccount))
    bankSeg = Trim(DLookup("COASegment", "BankAccountT", Forms!BankingF!cbxBankAccount))
    Form.Caption = bankCat & " " & bankSeg & " Account"
    'MsgBox CurrentDb.QueryDefs("CYBankTransactionQ").SQL
    requeryForm
    setupDefaults
    
End Sub

Private Sub setupDefaults()
    '
    '       Setup Search Defaults
    '
    dtmDateFromSearch = DMin("TransactionDate", "CYBankTransactionQ", "RegisterID=" & regID)
    dtmDateToSearch = DMax("TransactionDate", "CYBankTransactionQ", "RegisterID=" & regID)
    Me.Requery

End Sub

Private Sub dtmDateFromSearch_AfterUpdate()
    '
    '       Set Min Date Range
    '
    MsgBox "Min Date is " & dtmDateFromSearch
    Me.Requery
    
    
End Sub

Private Sub dtmDateToSearch_AfterUpdate()
    '
    '       Set Max Date Range
    '
    MsgBox "Max Date is " & dtmDateToSearch
    Me.Requery

End Sub

Note: requeryForm is the Subroutine taken from the Click to Sort video and it works correctly. Also, nothing in the setupDefaults Subroutine works.  That is, the Form is blank, (no records are displayed), the dtmDateFromSearch and dtmDateToSearch are blank when the Form is loaded.  If I enter dates in the dtmDateFromSearch and dtmdateToSearch fields and press return, no records are displayed.

Sorry, I have been confusing or have said things incorrectly.

Hope this helps
J David Bacon OP  @Reply  
    
3 years ago
Sorry, but I keep trying to fix this on my own.

I changed the TransactionDate on the CYTransactionQ Query by adding "Is Not Null" and the form loads displaying all the records correctly and the correct DMin/DMax Values (a Major Victory on my part).

But, when I change the Forms dtmDateFromSearch or the dtmDateToSearch the Afterupdate Event (Me.Requery) does not update the ...all the records are displayed instead of the date ranges in the search boxes.

I will await your reply and not make anymore changes.
Kevin Yip  @Reply  
     
3 years ago
Regarding setupDefaults(), if it isn't working, maybe the query CYBankTransactionQ has problems.  Check the SQL, and if you can't spot the problem, post it here and let me take a look.

Regarding all records being displayed when you enter in the date criteria, I look at your form's recordsource SQL again (which you posted above; if you have made changes to it since then, let me know).  Besides date criteria from textbox entries, you also have vendor name criteria and others from textbox entries in the SQL: [Forms]![BankRegisterF]![txtVendorNameSearch], etc.  And they seem to be connected by the OR operator.  You need to make sure the OR doesn't give you a problem here.  If your WHERE clause ends up looking like:

     (CYTransactionT.TransactionDate BETWEEN #1/4/21# AND #1/4/21#)  OR  (VendorNameT.VendorName LIKE *Some Company*)

Then your date criteria will be ignored as long as the vendor name part of the criteria is true.
J David Bacon OP  @Reply  
    
3 years ago
I just realized I did not mention the Bank Register Form (BankRegisterF) is loaded via a Docmd from another Form called BankListingF which uses BankAccountT as its RecordSource. A Bank Account is selected via a ComboBox called cbxBankAccount and has two (2) fields:BankRegisterID and BankName (BankRegisterID is hidden). When a bank is selected the following Subroutine is executed:

Private Sub btnViewRegister_Click()
    '
    '       View Selected Bank Transactions
    '
    If DCount("TransactionDate", "CYTransactionT", "RegisterID = cbxBankAccount") = 0 Then
        MsgBox "Select Another Bank...", vbOKOnly, "No Transactions To View"
        Exit Sub
    End If
    DoCmd.OpenForm "BankRegisterF", , "RegisterID=" & cbxBankAccount
      
End Sub

Note: BankRegisterF uses CYTranactionQ as its RecordSource for Sorting and Filter Bank Register Information.

Here is the problem:

The Criteria use for Filtering the TransactionDate does not work. Below are the various Criteria I have tried for the TransactionDate:
1. Is Null Or Between Forms!BankRegisterF!dtmDateFromSearch And Forms!BankRegisterF!dtmDateFromSearch
2. Is Not Null OR Between Forms!BankRegisterF!dtmDateFromSearch And Forms!BankRegisterF!dtmDateFromSearch
3. Between Forms!BankRegisterF!dtmDateFromSearch And Forms!BankRegisterF!dtmDateFromSearch

Here are the results (see above criteria) when Form RegisterF is Opened:
1. No records are displayed - Test for RegisterID in BankRegisterF via MsgBox is Null
2. All Records are displayed - Test for Date Search Fields (AfterUpdate Event) are not Filtered, all other Search Fields work Correctly
3. No records are displayed - Test for RegisterID in BankRegisterF via MsgBox is Null

Conclusion:
The only way Form RegisterF displays any records is via Criteria 2 above.  But the Date Search Fields in RegisterF do not display the records correctly.

I believe I have followed Rick's Search 2.0 Video, but I cannot get the same results.

Thank you for helping me with this problem. It seems I will have to remove the Date Search Feature from BankRegisterF until a solution is found.
Kevin Yip  @Reply  
     
3 years ago
Did my comment in the previous post about the vendor name help you?  Your date criteria is connected by an OR operation to your vendor name criteria.  As I said, if the latter criteria is true, the former won't work no matter what dates you put in.

If you are unable to correct this problem, you can remove the date criteria (or all criteria) from the SQL and use the form's Filter and FilterOn properties to set criteria.  That will make the SQL less complicated and easier to troubleshoot.
J David Bacon OP  @Reply  
    
3 years ago
The other two (2) criteria are connected with AND, I only used the OR condition to see if that fixed the problem.  I will try try the Form Filter ands Filteron properties.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Search Form 2.0.
 

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: 4/15/2026 6:14:08 PM. PLT: 1s