Results 1 to 9 of 9

calendar build problem in XL2010, OK in XL2003

Threaded View

  1. #1
    Valued Forum Contributor jwright650's Avatar
    Join Date
    12-10-2010
    Location
    Va, USA
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    606

    calendar build problem in XL2010, OK in XL2003

    Using this code below to build a calendar userform, this works fine in 2003 but 2010 has a problem with this line:
    ThisDay = Date
    and this line
    Format(ThisDay, "mm")
    Private Sub UserForm_Initialize()
        Application.EnableEvents = False
        'starts the form on todays date
        ThisDay = Date
        ThisMth = Format(ThisDay, "mm")
        ThisYear = Format(ThisDay, "yyyy")
        For i = 1 To 12
            CB_Mth.AddItem Format(DateSerial(Year(Date), Month(Date) + i, 0), "mmmm")
        Next
        CB_Mth.ListIndex = Format(Date, "mm") - Format(Date, "mm")
        For i = -20 To 50
            If i = 1 Then CB_Yr.AddItem Format((ThisDay), "yyyy") Else CB_Yr.AddItem _
                Format((DateAdd("yyyy", (i - 1), ThisDay)), "yyyy")
        Next
        CB_Yr.ListIndex = 21
        'Builds the calendar with todays date
        CalendarFrmNC1.Width = CalendarFrmNC1.Width
        CreateCal = True
        Call Build_Calendar
        Application.EnableEvents = True
    End Sub
    Private Sub CB_Mth_Change()
        'rebuilds the calendar when the month is changed by the user
        Build_Calendar
    End Sub
    Private Sub CB_Yr_Change()
        'rebuilds the calendar when the year is changed by the user
        Build_Calendar
    End Sub
    Private Sub Build_Calendar()
        'the routine that actually builds the calendar each time
        If CreateCal = True Then
        CalendarFrmNC1.Caption = " " & CB_Mth.Value & " " & CB_Yr.Value
        'sets the focus for the todays date button
        CommandButton1.SetFocus
        For i = 1 To 42
            If i < Weekday((CB_Mth.Value) & "/1/" & (CB_Yr.Value)) Then
                Controls("D" & (i)).Caption = Format(DateAdd("d", (i - Weekday((CB_Mth.Value) & "/1/" & (CB_Yr.Value))), _
                    ((CB_Mth.Value) & "/1/" & (CB_Yr.Value))), "d")
                Controls("D" & (i)).ControlTipText = Format(DateAdd("d", (i - Weekday((CB_Mth.Value) & "/1/" & (CB_Yr.Value))), _
                    ((CB_Mth.Value) & "/1/" & (CB_Yr.Value))), "m/d/yy")
            ElseIf i >= Weekday((CB_Mth.Value) & "/1/" & (CB_Yr.Value)) Then
                Controls("D" & (i)).Caption = Format(DateAdd("d", (i - Weekday((CB_Mth.Value) _
                    & "/1/" & (CB_Yr.Value))), ((CB_Mth.Value) & "/1/" & (CB_Yr.Value))), "d")
                Controls("D" & (i)).ControlTipText = Format(DateAdd("d", (i - Weekday((CB_Mth.Value) & "/1/" & (CB_Yr.Value))), _
                    ((CB_Mth.Value) & "/1/" & (CB_Yr.Value))), "m/d/yy")
            End If
            If Format(DateAdd("d", (i - Weekday((CB_Mth.Value) & "/1/" & (CB_Yr.Value))), _
            ((CB_Mth.Value) & "/1/" & (CB_Yr.Value))), "mmmm") = ((CB_Mth.Value)) Then
                If Controls("D" & (i)).BackColor <> &H80000016 Then Controls("D" & (i)).BackColor = &H80000018  '&H80000010
                Controls("D" & (i)).Font.Bold = True
            If Format(DateAdd("d", (i - Weekday((CB_Mth.Value) & "/1/" & (CB_Yr.Value))), _
                ((CB_Mth.Value) & "/1/" & (CB_Yr.Value))), "m/d/yy") = Format(ThisDay, "m/d/yy") Then Controls("D" & (i)).SetFocus
            Else
                If Controls("D" & (i)).BackColor <> &H80000016 Then Controls("D" & (i)).BackColor = &H8000000F
                Controls("D" & (i)).Font.Bold = False
            End If
        Next
        End If
    End Sub
    Private Sub D1_Click()
        'this sub and the ones following represent the buttons for days on the form
        'retrieves the current value of the individual controltiptext and
        'places it in the active cell
        frmNCReport.txtDate1NCform.Value = D1.ControlTipText
        Unload Me
        'after unload you can call a different userform to continue data entry
        'uncomment this line and add a userform named UserForm2
        'Userform2.Show
        
    End Sub
    Private Sub D2_Click()
        frmNCReport.txtDate1NCform.Value = D2.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D3_Click()
        frmNCReport.txtDate1NCform.Value = D3.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D4_Click()
        frmNCReport.txtDate1NCform.Value = D4.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D5_Click()
        frmNCReport.txtDate1NCform.Value = D5.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D6_Click()
        frmNCReport.txtDate1NCform.Value = D6.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D7_Click()
        frmNCReport.txtDate1NCform.Value = D7.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D8_Click()
        frmNCReport.txtDate1NCform.Value = D8.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D9_Click()
        frmNCReport.txtDate1NCform.Value = D9.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D10_Click()
        frmNCReport.txtDate1NCform.Value = D10.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D11_Click()
        frmNCReport.txtDate1NCform.Value = D11.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D12_Click()
        frmNCReport.txtDate1NCform.Value = D12.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D13_Click()
        frmNCReport.txtDate1NCform.Value = D13.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D14_Click()
        frmNCReport.txtDate1NCform.Value = D14.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D15_Click()
        frmNCReport.txtDate1NCform.Value = D15.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D16_Click()
        frmNCReport.txtDate1NCform.Value = D16.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D17_Click()
        frmNCReport.txtDate1NCform.Value = D17.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D18_Click()
        frmNCReport.txtDate1NCform.Value = D18.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D19_Click()
        frmNCReport.txtDate1NCform.Value = D19.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D20_Click()
        frmNCReport.txtDate1NCform.Value = D20.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D21_Click()
        frmNCReport.txtDate1NCform.Value = D21.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D22_Click()
        frmNCReport.txtDate1NCform.Value = D22.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D23_Click()
        frmNCReport.txtDate1NCform.Value = D23.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D24_Click()
        frmNCReport.txtDate1NCform.Value = D24.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D25_Click()
        frmNCReport.txtDate1NCform.Value = D25.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D26_Click()
        frmNCReport.txtDate1NCform.Value = D26.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D27_Click()
        frmNCReport.txtDate1NCform.Value = D27.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D28_Click()
        frmNCReport.txtDate1NCform.Value = D28.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D29_Click()
        frmNCReport.txtDate1NCform.Value = D29.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D30_Click()
        frmNCReport.txtDate1NCform.Value = D30.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D31_Click()
        frmNCReport.txtDate1NCform.Value = D31.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D32_Click()
        frmNCReport.txtDate1NCform.Value = D32.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D33_Click()
        frmNCReport.txtDate1NCform.Value = D33.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D34_Click()
        frmNCReport.txtDate1NCform.Value = D34.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D35_Click()
        frmNCReport.txtDate1NCform.Value = D35.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D36_Click()
        frmNCReport.txtDate1NCform.Value = D36.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D37_Click()
        frmNCReport.txtDate1NCform.Value = D37.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D38_Click()
        frmNCReport.txtDate1NCform.Value = D38.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D39_Click()
        frmNCReport.txtDate1NCform.Value = D39.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D40_Click()
        frmNCReport.txtDate1NCform.Value = D40.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D41_Click()
        frmNCReport.txtDate1NCform.Value = D41.ControlTipText
        Unload Me
        
    End Sub
    Private Sub D42_Click()
        frmNCReport.txtDate1NCform.Value = D42.ControlTipText
        Unload Me
        
    End Sub
    Last edited by jwright650; 03-24-2011 at 10:09 AM. Reason: hit submit too soon
    Life is like a roll of toilet paper. The closer it gets to the end, the faster it goes.
    John Wright

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1