Calendar

  • Thread starter Thread starter Loi
  • Start date Start date
L

Loi

Hi,
I inserted a calendar in a form. It works ok.

However, By default, the month of the calendar is July.
(Whenever I open the form, July always appears on the
calendar.)
Please show me how to made it to current month. EX: this
month is October.

Thanks
Loi
 
hi,
usually the code behind the calendar sets the defaults
for the calander. Aparently your calendar defaults to
july. you will have to re-code the calendar to make it
default to the current month.
here is the code for my calendar. this code is for excel
but i also have it in access. you can use it as a example.
-------------------------------------------------
Option Explicit
-------------------------------------------------
Private Sub lblUp_Click()
Me![scrCDate] = DateAdd("m", 1, Me![scrCDate])
Call userform_Click
End Sub
--------------------------------------------------
Private Sub lblDown_click()
Me![scrCDate] = DateAdd("m", -1, Me![scrCDate])
Call userform_Click
End Sub
---------------------------------------------------
Private Sub Userform_Initialize()
Dim D1 As Variant, D2 As Integer, D3 As Integer
Dim textD1 As Long
Me![scrCDate] = DateSerial(Year(Date), Month(Date), 1)
Me![scrMonth] = Format(Date, "mmmm")
Me![scrYear] = Format(Date, "yyyy")
Me![scrMonth] = Format(Me![scrCDate], "mmmm")
Me![scrYear] = Format(Me![scrCDate], "yyyy")
D1 = DateSerial(Year(Me![scrCDate]), Month(Me!
[scrCDate]), 1)
D2 = DatePart("w", D1, vbMonday)
Do Until DatePart("w", D1, vbSunday) = 1
D1 = DateAdd("d", -1, D1)
Loop
Me![scr1Date] = D1
D3 = 1
Do Until D3 > 42
Me("C" & Format(D3, "00")) = Day(D1)
If Month(D1) <> Month(Me![scrCDate]) Then
Me("C" & Format(D3, "00")).ForeColor = 8421504
Me("C" & Format(D3, "00")).FontWeight = 400
Else
Me("C" & Format(D3, "00")).ForeColor = 0
Me("C" & Format(D3, "00")).FontWeight = 700
End If
If D1 = Date Then
Me("C" & Format(D3, "00")).BackColor = &H8080FF
End If
D3 = D3 + 1
D1 = DateAdd("d", 1, D1)
Loop
Me.Repaint
End Sub
-----------------------------------------------
Private Sub userform_Click() 'Sub RefDates()

Dim D1 As Variant, D2 As Integer, D3 As Integer
Dim textD1 As String
Dim stgSQL As String
Me![scrMonth] = Format(Me![scrCDate], "mmmm")
Me![scrYear] = Format(Me![scrCDate], "yyyy")
D1 = DateSerial(Year(Me![scrCDate]), Month(Me!
[scrCDate]), 1)
D2 = DatePart("w", D1, vbMonday)
Do Until DatePart("w", D1, vbSunday) = 1
D1 = DateAdd("d", -1, D1)
Loop
Me![scr1Date] = D1
D3 = 1
Do Until D3 > 42
Me("C" & Format(D3, "00")) = Day(D1)
If Month(D1) <> Month(Me![scrCDate]) Then
Me("C" & Format(D3, "00")).ForeColor = 8421504
Me("C" & Format(D3, "00")).FontWeight = 400
Else
Me("C" & Format(D3, "00")).ForeColor = 0
Me("C" & Format(D3, "00")).FontWeight = 700
End If
If D1 = Date Then
Me("C" & Format(D3, "00")).BackColor = &H8080FF
Else
Me("C" & Format(D3, "00")).BackColor = &HFFFFFF
End If
D3 = D3 + 1
D1 = DateAdd("d", 1, D1)
Loop
Me.Repaint

End Sub
---------------------------------------------------------
Private Sub Command107_Click()
On Error GoTo Err_Command107_Click
DoCmd.Close
Exit_Command107_Click:
Exit Sub
Err_Command107_Click:
MsgBox Err.Description
Resume Exit_Command107_Click

End Sub
 
Whoa!
We're talking the Calendar control here:
Private Sub Form_Load()
Me.ActiveXCtl0.Value = Date
End Sub

will do it, just substitute the name of your control.

--
HTH
Dan Artuso, Access MVP


Frank Stone said:
hi,
usually the code behind the calendar sets the defaults
for the calander. Aparently your calendar defaults to
july. you will have to re-code the calendar to make it
default to the current month.
here is the code for my calendar. this code is for excel
but i also have it in access. you can use it as a example.
-------------------------------------------------
Option Explicit
-------------------------------------------------
Private Sub lblUp_Click()
Me![scrCDate] = DateAdd("m", 1, Me![scrCDate])
Call userform_Click
End Sub
--------------------------------------------------
Private Sub lblDown_click()
Me![scrCDate] = DateAdd("m", -1, Me![scrCDate])
Call userform_Click
End Sub
---------------------------------------------------
Private Sub Userform_Initialize()
Dim D1 As Variant, D2 As Integer, D3 As Integer
Dim textD1 As Long
Me![scrCDate] = DateSerial(Year(Date), Month(Date), 1)
Me![scrMonth] = Format(Date, "mmmm")
Me![scrYear] = Format(Date, "yyyy")
Me![scrMonth] = Format(Me![scrCDate], "mmmm")
Me![scrYear] = Format(Me![scrCDate], "yyyy")
D1 = DateSerial(Year(Me![scrCDate]), Month(Me!
[scrCDate]), 1)
D2 = DatePart("w", D1, vbMonday)
Do Until DatePart("w", D1, vbSunday) = 1
D1 = DateAdd("d", -1, D1)
Loop
Me![scr1Date] = D1
D3 = 1
Do Until D3 > 42
Me("C" & Format(D3, "00")) = Day(D1)
If Month(D1) <> Month(Me![scrCDate]) Then
Me("C" & Format(D3, "00")).ForeColor = 8421504
Me("C" & Format(D3, "00")).FontWeight = 400
Else
Me("C" & Format(D3, "00")).ForeColor = 0
Me("C" & Format(D3, "00")).FontWeight = 700
End If
If D1 = Date Then
Me("C" & Format(D3, "00")).BackColor = &H8080FF
End If
D3 = D3 + 1
D1 = DateAdd("d", 1, D1)
Loop
Me.Repaint
End Sub
-----------------------------------------------
Private Sub userform_Click() 'Sub RefDates()

Dim D1 As Variant, D2 As Integer, D3 As Integer
Dim textD1 As String
Dim stgSQL As String
Me![scrMonth] = Format(Me![scrCDate], "mmmm")
Me![scrYear] = Format(Me![scrCDate], "yyyy")
D1 = DateSerial(Year(Me![scrCDate]), Month(Me!
[scrCDate]), 1)
D2 = DatePart("w", D1, vbMonday)
Do Until DatePart("w", D1, vbSunday) = 1
D1 = DateAdd("d", -1, D1)
Loop
Me![scr1Date] = D1
D3 = 1
Do Until D3 > 42
Me("C" & Format(D3, "00")) = Day(D1)
If Month(D1) <> Month(Me![scrCDate]) Then
Me("C" & Format(D3, "00")).ForeColor = 8421504
Me("C" & Format(D3, "00")).FontWeight = 400
Else
Me("C" & Format(D3, "00")).ForeColor = 0
Me("C" & Format(D3, "00")).FontWeight = 700
End If
If D1 = Date Then
Me("C" & Format(D3, "00")).BackColor = &H8080FF
Else
Me("C" & Format(D3, "00")).BackColor = &HFFFFFF
End If
D3 = D3 + 1
D1 = DateAdd("d", 1, D1)
Loop
Me.Repaint

End Sub
---------------------------------------------------------
Private Sub Command107_Click()
On Error GoTo Err_Command107_Click
DoCmd.Close
Exit_Command107_Click:
Exit Sub
Err_Command107_Click:
MsgBox Err.Description
Resume Exit_Command107_Click

End Sub
-----------------------------------------------
Sub ShowForm()
CalForm.Show 0
AppActivate Application.Caption
End Sub
------------------------------------------------
Regards
Frank
-----Original Message-----
Hi,
I inserted a calendar in a form. It works ok.

However, By default, the month of the calendar is July.
(Whenever I open the form, July always appears on the
calendar.)
Please show me how to made it to current month. EX: this
month is October.

Thanks
Loi
.
 
Back
Top