Results 1 to 2 of 2
  1. #1
    cmb is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Sep 2014
    Posts
    11

    Help formatting calendar dates

    Hi there,

    I hope someone can help me with this! I have put together a functional calender which opens to the current month, finds the first Sunday and greys out any days that are not in the current month. I have added navigation buttons to move to the next and previous month but am having a problem looping through the days to change the dates set to each day. Each of the 42 day fields has a date field named Date1~Date42. With the code below the Date1 updates fine but the Date2~Date42 in the for loop do not. What am I doing wrong?

    Many thanks!

    Private Sub MonthForward_Click()

    Dim X1 As Integer
    Dim X2 As Integer
    Dim S1 As String
    Dim S2 As String
    Dim S3 As String



    StartDate = DateSerial(Year(Date7), Month(Date7) + 1, 1)

    While Weekday(StartDate) <> 1
    StartDate = StartDate - 1
    Wend

    Date1 = StartDate

    For X1 = 1 To 42
    X2 = X1 + 1
    S1 = "Date" & X1
    S2 = "Day" & X1
    S3 = "Date" & X2

    S3 = S3 & " = " & StartDate + X1

    If Month(Forms!frmMonthlyCalendar(S1)) <> Month(Date7) Then
    Forms!frmMonthlyCalendar(S1).BackColor = &HA5A5A5
    Forms!frmMonthlyCalendar(S2).BackColor = &HBFBFBF
    End If

    Next X1

    End Sub

  2. #2
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742

    A code snippet to try

    S1 will be the string "Date12", not the field Date12.
    S2 will be the string "Day12"
    S3 will be a string that reads "Date12 = [somedatevalue]"

    No code has been executed to make that S3 string DO anything.

    Try something like this
    Code:
    For X1 = 1 To 42
        X2 = X1 + 1
        S1 = "Date" & X1 
        S2 = "Day" & X1
    
        With Forms
            !frmMonthlyCalendar(S1) = StartDate + X1
            If Month(frmMonthlyCalendar(S1)) <> Month(Date7) Then
                 !frmMonthlyCalendar(S1).BackColor = &HA5A5A5
                 !frmMonthlyCalendar(S2).BackColor = &HBFBFBF
             End If
        End With
    
     Next X1
    For efficiency, I'd really like to make that
    Code:
    With Forms!frmMonthlyCalendar
    or
    Code:
    With Forms!frmMonthlyCalendar(S1)
    but then I'd have to test whether the proper reference would be to .Item or .Value or whatever to make the rest of it work right. If anyone knows that off the top of their head, please feel free to school me with a code sample.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Calendar Button to Select Dates
    By CementCarver in forum Forms
    Replies: 9
    Last Post: 04-20-2013, 09:15 AM
  2. Replies: 5
    Last Post: 08-20-2012, 11:11 PM
  3. Custom calendar - select multiple dates
    By larek in forum Access
    Replies: 6
    Last Post: 06-23-2011, 02:40 AM
  4. Calendar to and From Dates
    By bobfin in forum Reports
    Replies: 10
    Last Post: 08-05-2010, 07:05 PM
  5. Replies: 2
    Last Post: 04-23-2010, 01:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums