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 
Setting Up a Calendar blanks
William Kennedy 
    
3 years ago
T need to load a table, CalendarT with blank records except for the Date field, DateTime.  The records start Jan 1 and end Dec 31 of the year listed in Text box YearNo.  I can't seem to get it to work.  It seems simple but is not.
Sami Shamma  @Reply  
             
3 years ago
William
do you know VBA and SQL? if yes you can use a FOR/NEXT loop to insert into the table with one SQL statement. if you can not do it I will write the code for you.
Kevin Robertson  @Reply  
           
3 years ago
A simple For Next Loop but you do need to know how many days are in that particular year.

    Dim X As Long, DaysInYear As Long, StartDate As Date
    
    StartDate = DateSerial(txtYear, 1, 0)
    DaysInYear = DateDiff("d", StartDate, DateSerial(txtYear, 12, 31))
    
    For X = 1 To DaysInYear
        StartDate = DateAdd("d", 1, StartDate)
        CurrentDb.Execute "INSERT INTO CalendarT([DateTime]) " & _
            "VALUES(#" & StartDate & "#)"
    Next

    MsgBox "Dates Added!", vbInformation, "Success"
Kevin Robertson  @Reply  
           
3 years ago
I would also add some error handling to the above code to ensure a valid year is entered in the Text Box.
For example:

    If Not IsNumeric(txtYear) Or InStr(txtYear, ".") <> 0 Or Len(txtYear) <> 4 Then
        MsgBox "Please enter a valid 4 digit year.", vbCritical, "Invalid Year"
        Exit Sub
    End If
William Kennedy OP  @Reply  
    
2 years ago
thanks

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/7/2026 9:56:54 AM. PLT: 0s