Actual Date

A

Alimbilo

How can I have a form to show the actual date as soon as it open and have the
data empty ready for input?

I tried "On Current" but it doesn't let me move back to a previous date.

Thanks.
 
K

Klatuu

Well, there isn't enough information in your post to give you an exact
answer. It really depends on whether the control you want to show the date
in is a bound or unbound control. It also depends on whether you are opening
the form in edit or add mode.
A more detailed description would be useful.
 
A

Alimbilo

Ok.
The Date is a bound control.
What I am trying to do is whenever I click on the Date I choose in the
calendar, I want all the fields value to be the records that I have put on
that day.

Right now, I have a popup calendar but It doesn't really do what I want. I
click on the date but nothing change in the fields.

Hope you understand me. Thanks
 
K

Klatuu

Are you saying you want to choose a date and have your form only show records
that have a date field that is equal to the date you choose?

If so, use the After Update event of the control where you choose the date
to set the form's Filter and Filteron properties.
 
A

Alimbilo

Yes, I am.
How do I set the Form Filter and Filterons properties?
And in the After Update event, what should I put in there.
 
K

Klatuu

Me.Filter = "[NameOfDateField] = #" & Me.DateControl & "#"
Me.FilterOn = True

[NameOfDateField] would be the name of the field in the form's record source
you want to filter on and Me.DateControl would be the name of the control you
enter the date in. It would be in the After Update event of that control.
 
A

Alimbilo

This is how the all concept is.
I have download the Calendar DB from an MVP website. and they have given
instruction hoe to configure it on your own website.

That Calendar has 2 part:
1. a module:
Option Compare Database
Option Explicit

'Calendar form variable:
Public gtxtCalTarget As TextBox 'Text box to return the date from the
calendar to.

Public Function CalendarFor(txt As TextBox, Optional strTitle As String)
'On Error GoTo Err_Handler
'Purpose: Open the calendar form, identifying the text box to return
the date to.
'Arguments: txt = the text box to return the date to.
' strTitle = the caption for the calendar form (passed in
OpenArgs).

Set gtxtCalTarget = txt
DoCmd.OpenForm "frmCalendar", windowmode:=acDialog, OpenArgs:=strTitle

Exit_Handler:
Exit Function

Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description, vbExclamation,
"CalendarFor()"
Resume Exit_Handler
End Function

Public Function LogError(lngErr As Long, strDescrip As String, strProc As
String, _
Optional bShowUser As Boolean = True, Optional varParam As Variant)
'Purpose: Minimal substitute for the real error logger function at:
' http://allenbrowne.com/ser-23a.html

If bShowUser Then
MsgBox "Error " & lngErr & ": " & strDescrip, vbExclamation, strProc
End If
End Function


And a Form which contains this code:

'Copyright: Allen Browne's Database And Training, 2007.
'Author: Allen Browne. (e-mail address removed)
Option Compare Database
Option Explicit

Private Const conMod = "frmCalendar"

Private Sub cmdCancel_Click()
On Error GoTo Err_Handler
'Purpose: Close without transferring date back to calling text box.

DoCmd.Close acForm, Me.Name, acSaveNo

Exit_Handler:
Exit Sub

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".cmdCancel_Click")
Resume Exit_Handler
End Sub

Private Sub cmdMonthDown_Click()
Call SetDate("M", -1)
End Sub
Private Sub cmdMonthUp_Click()
Call SetDate("M", 1)
End Sub

Private Sub cmdOk_Click()
On Error Resume Next
'Purpose: Transfer the result back to the calling text box (if there
is one), and close.

If Me.cmdOk.Enabled Then
If gtxtCalTarget = Me.txtDate Then
'do nothing
Else
gtxtCalTarget = Me.txtDate
End If
End If
gtxtCalTarget.SetFocus
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub

Private Sub cmdToday_Click()
'On Error GoTo Err_Handler
'Purpose: Set today.

Me.txtDate = Date
Call ShowCal

Exit_Handler:
Exit Sub

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".cmdToday_Click")
Resume Exit_Handler
End Sub

Private Sub cmdYearDown_Click()
Call SetDate("YYYY", -1)
End Sub
Private Sub cmdYearUp_Click()
Call SetDate("YYYY", 1)
End Sub

Private Sub Form_AfterUpdate()
Me.Filter = "[Date] = #" & Me.Calendar & "#"
Me.FilterOn = True
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'On Error GoTo Err_Handler
'Purpose:

With Me.txtDate
Select Case KeyCode
Case vbKeyLeft '1 day left or right.
.Value = .Value - 1
KeyCode = 0
Call ShowCal
Case vbKeyRight
.Value = .Value + 1
KeyCode = 0
Call ShowCal
Case vbKeyUp '1 week up or down.
.Value = .Value - 7
KeyCode = 0
Call ShowCal
Case vbKeyDown
.Value = .Value + 7
KeyCode = 0
Call ShowCal
Case vbKeyHome 'Home/End = first/last of this month.
.Value = .Value - Day(.Value) + 1
KeyCode = 0
Call ShowCal
Case vbKeyEnd
.Value = DateSerial(Year(.Value), Month(.Value) + 1, 0)
KeyCode = 0
Call ShowCal
Case vbKeyPageUp 'PgUp/PgDn = previous/next month.
.Value = DateAdd("m", -1, .Value)
KeyCode = 0
Call ShowCal
Case vbKeyPageDown
.Value = DateAdd("m", 1, .Value)
KeyCode = 0
Call ShowCal
Case vbKeyT, vbKeyT + 32 'T or t = today
.Value = Date
KeyCode = 0
Call ShowCal
End Select
End With

Exit_Handler:
Exit Sub

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".Form_KeyDown")
Resume Exit_Handler
End Sub

Private Sub Form_Open(Cancel As Integer)
'On Error GoTo Form_Open_Err
Dim bEnabled As Boolean

'Initialize to the existing date, or today if null.
If IsDate(gtxtCalTarget) Then
Me.txtDate = gtxtCalTarget.Value
Else
Me.txtDate = Date
End If

'Lock the Ok button if the text box is locked or disabled.
bEnabled = (gtxtCalTarget.Enabled) And (Not gtxtCalTarget.Locked)
With Me.cmdOk
If .Enabled <> bEnabled Then
.Enabled = bEnabled
End If
End With

'Set the title
If Len(Me.OpenArgs) > 0& Then
Me.Caption = Me.OpenArgs
End If

'Set up the calendar for this month.
Call ShowCal

Form_Open_Exit:
Exit Sub

Form_Open_Err:
MsgBox Err.Description, vbCritical, "frmCalendar.Form_Open"
Resume Form_Open_Exit
End Sub

Private Function SetSelected(ctlName As String)
On Error GoTo Err_Handler

Me.txtDate = DateSerial(Year(txtDate), Month(txtDate),
CLng(Me(ctlName).Caption))
Call ShowHighligher(ctlName)

Exit_Handler:
Exit Function

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".SetSelected")
Resume Exit_Handler
End Function

Private Function SelectDate(ctlName As String)
Call SetSelected(ctlName)
Call cmdOk_Click
End Function

Private Function SetDate(Subject As String, Optional intStep As Integer = 1)
On Error GoTo Err_Handler

Me.txtDate = DateAdd(Subject, intStep, Me.txtDate)
Call ShowCal

Exit_Handler:
Exit Function

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".SetDate")
Resume Exit_Handler
End Function

Private Function ShowCal() As Boolean
On Error GoTo Err_Handler
'Purpose:
Dim dtStartDate As Date 'First of month
Dim iDays As Integer 'Days in month
Dim iOffset As Integer 'Offset to first label for month.
Dim i As Integer 'Loop controller.
Dim iDay As Integer 'Day under consideration.
Dim bShow As Boolean 'Flag: show label

dtStartDate = Me.txtDate - Day(Me.txtDate) + 1 'First of month
iDays = Day(DateAdd("m", 1, dtStartDate) - 1) 'Days in month.
iOffset = Weekday(dtStartDate, vbSunday) - 2 'Offset to first label
for month.

For i = 0 To 41
With Me("lblDay" & Format(i, "00"))
iDay = i - iOffset
bShow = ((iDay > 0) And (iDay <= iDays))
If .Visible <> bShow Then
.Visible = bShow
End If
If (bShow) And (.Caption <> iDay) Then
.Caption = iDay
End If
End With
Next

Call ShowHighligher("lblDay" & Format(Day(Me.txtDate) + iOffset, "00"))

Exit_Handler:
Exit Function

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".ShowCal")
Resume Exit_Handler
End Function

Private Function ShowHighligher(ctlName As String)
On Error GoTo Err_Handler
Const lngcVOffset As Long = -83

With Me(ctlName)
Me.lblHighlight.Left = .Left
Me.lblHighlight.Top = .Top + lngcVOffset
End With

Exit_Handler:
Exit Function

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".ShowHighligher")
Resume Exit_Handler
End Function

Private Sub lblHelp_Click()
MsgBox Me.lblHelp.ControlTipText, vbInformation, "Calendar help"
End Sub


Which one is the Control Name for the Calendar? That where I am confuse.
In my for the Calendar does Popup really good and I have the Date field
change whenever I pick a date. That part works fine but the Filter Part
doesn't.

I really appreciate your help. Really Do.



Klatuu said:
Me.Filter = "[NameOfDateField] = #" & Me.DateControl & "#"
Me.FilterOn = True

[NameOfDateField] would be the name of the field in the form's record source
you want to filter on and Me.DateControl would be the name of the control you
enter the date in. It would be in the After Update event of that control.
--
Dave Hargis, Microsoft Access MVP


Alimbilo said:
Yes, I am.
How do I set the Form Filter and Filterons properties?
And in the After Update event, what should I put in there.
 
K

Klatuu

The filtering code does not go in the calendar form. It goes in the control
on your form where you call the calander. It returns the value to your form,
then you use the After Update event of the control on your form.
--
Dave Hargis, Microsoft Access MVP


Alimbilo said:
This is how the all concept is.
I have download the Calendar DB from an MVP website. and they have given
instruction hoe to configure it on your own website.

That Calendar has 2 part:
1. a module:
Option Compare Database
Option Explicit

'Calendar form variable:
Public gtxtCalTarget As TextBox 'Text box to return the date from the
calendar to.

Public Function CalendarFor(txt As TextBox, Optional strTitle As String)
'On Error GoTo Err_Handler
'Purpose: Open the calendar form, identifying the text box to return
the date to.
'Arguments: txt = the text box to return the date to.
' strTitle = the caption for the calendar form (passed in
OpenArgs).

Set gtxtCalTarget = txt
DoCmd.OpenForm "frmCalendar", windowmode:=acDialog, OpenArgs:=strTitle

Exit_Handler:
Exit Function

Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description, vbExclamation,
"CalendarFor()"
Resume Exit_Handler
End Function

Public Function LogError(lngErr As Long, strDescrip As String, strProc As
String, _
Optional bShowUser As Boolean = True, Optional varParam As Variant)
'Purpose: Minimal substitute for the real error logger function at:
' http://allenbrowne.com/ser-23a.html

If bShowUser Then
MsgBox "Error " & lngErr & ": " & strDescrip, vbExclamation, strProc
End If
End Function


And a Form which contains this code:

'Copyright: Allen Browne's Database And Training, 2007.
'Author: Allen Browne. (e-mail address removed)
Option Compare Database
Option Explicit

Private Const conMod = "frmCalendar"

Private Sub cmdCancel_Click()
On Error GoTo Err_Handler
'Purpose: Close without transferring date back to calling text box.

DoCmd.Close acForm, Me.Name, acSaveNo

Exit_Handler:
Exit Sub

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".cmdCancel_Click")
Resume Exit_Handler
End Sub

Private Sub cmdMonthDown_Click()
Call SetDate("M", -1)
End Sub
Private Sub cmdMonthUp_Click()
Call SetDate("M", 1)
End Sub

Private Sub cmdOk_Click()
On Error Resume Next
'Purpose: Transfer the result back to the calling text box (if there
is one), and close.

If Me.cmdOk.Enabled Then
If gtxtCalTarget = Me.txtDate Then
'do nothing
Else
gtxtCalTarget = Me.txtDate
End If
End If
gtxtCalTarget.SetFocus
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub

Private Sub cmdToday_Click()
'On Error GoTo Err_Handler
'Purpose: Set today.

Me.txtDate = Date
Call ShowCal

Exit_Handler:
Exit Sub

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".cmdToday_Click")
Resume Exit_Handler
End Sub

Private Sub cmdYearDown_Click()
Call SetDate("YYYY", -1)
End Sub
Private Sub cmdYearUp_Click()
Call SetDate("YYYY", 1)
End Sub

Private Sub Form_AfterUpdate()
Me.Filter = "[Date] = #" & Me.Calendar & "#"
Me.FilterOn = True
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'On Error GoTo Err_Handler
'Purpose:

With Me.txtDate
Select Case KeyCode
Case vbKeyLeft '1 day left or right.
.Value = .Value - 1
KeyCode = 0
Call ShowCal
Case vbKeyRight
.Value = .Value + 1
KeyCode = 0
Call ShowCal
Case vbKeyUp '1 week up or down.
.Value = .Value - 7
KeyCode = 0
Call ShowCal
Case vbKeyDown
.Value = .Value + 7
KeyCode = 0
Call ShowCal
Case vbKeyHome 'Home/End = first/last of this month.
.Value = .Value - Day(.Value) + 1
KeyCode = 0
Call ShowCal
Case vbKeyEnd
.Value = DateSerial(Year(.Value), Month(.Value) + 1, 0)
KeyCode = 0
Call ShowCal
Case vbKeyPageUp 'PgUp/PgDn = previous/next month.
.Value = DateAdd("m", -1, .Value)
KeyCode = 0
Call ShowCal
Case vbKeyPageDown
.Value = DateAdd("m", 1, .Value)
KeyCode = 0
Call ShowCal
Case vbKeyT, vbKeyT + 32 'T or t = today
.Value = Date
KeyCode = 0
Call ShowCal
End Select
End With

Exit_Handler:
Exit Sub

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".Form_KeyDown")
Resume Exit_Handler
End Sub

Private Sub Form_Open(Cancel As Integer)
'On Error GoTo Form_Open_Err
Dim bEnabled As Boolean

'Initialize to the existing date, or today if null.
If IsDate(gtxtCalTarget) Then
Me.txtDate = gtxtCalTarget.Value
Else
Me.txtDate = Date
End If

'Lock the Ok button if the text box is locked or disabled.
bEnabled = (gtxtCalTarget.Enabled) And (Not gtxtCalTarget.Locked)
With Me.cmdOk
If .Enabled <> bEnabled Then
.Enabled = bEnabled
End If
End With

'Set the title
If Len(Me.OpenArgs) > 0& Then
Me.Caption = Me.OpenArgs
End If

'Set up the calendar for this month.
Call ShowCal

Form_Open_Exit:
Exit Sub

Form_Open_Err:
MsgBox Err.Description, vbCritical, "frmCalendar.Form_Open"
Resume Form_Open_Exit
End Sub

Private Function SetSelected(ctlName As String)
On Error GoTo Err_Handler

Me.txtDate = DateSerial(Year(txtDate), Month(txtDate),
CLng(Me(ctlName).Caption))
Call ShowHighligher(ctlName)

Exit_Handler:
Exit Function

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".SetSelected")
Resume Exit_Handler
End Function

Private Function SelectDate(ctlName As String)
Call SetSelected(ctlName)
Call cmdOk_Click
End Function

Private Function SetDate(Subject As String, Optional intStep As Integer = 1)
On Error GoTo Err_Handler

Me.txtDate = DateAdd(Subject, intStep, Me.txtDate)
Call ShowCal

Exit_Handler:
Exit Function

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".SetDate")
Resume Exit_Handler
End Function

Private Function ShowCal() As Boolean
On Error GoTo Err_Handler
'Purpose:
Dim dtStartDate As Date 'First of month
Dim iDays As Integer 'Days in month
Dim iOffset As Integer 'Offset to first label for month.
Dim i As Integer 'Loop controller.
Dim iDay As Integer 'Day under consideration.
Dim bShow As Boolean 'Flag: show label

dtStartDate = Me.txtDate - Day(Me.txtDate) + 1 'First of month
iDays = Day(DateAdd("m", 1, dtStartDate) - 1) 'Days in month.
iOffset = Weekday(dtStartDate, vbSunday) - 2 'Offset to first label
for month.

For i = 0 To 41
With Me("lblDay" & Format(i, "00"))
iDay = i - iOffset
bShow = ((iDay > 0) And (iDay <= iDays))
If .Visible <> bShow Then
.Visible = bShow
End If
If (bShow) And (.Caption <> iDay) Then
.Caption = iDay
End If
End With
Next

Call ShowHighligher("lblDay" & Format(Day(Me.txtDate) + iOffset, "00"))

Exit_Handler:
Exit Function

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".ShowCal")
Resume Exit_Handler
End Function

Private Function ShowHighligher(ctlName As String)
On Error GoTo Err_Handler
Const lngcVOffset As Long = -83

With Me(ctlName)
Me.lblHighlight.Left = .Left
Me.lblHighlight.Top = .Top + lngcVOffset
End With

Exit_Handler:
Exit Function

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".ShowHighligher")
Resume Exit_Handler
End Function

Private Sub lblHelp_Click()
MsgBox Me.lblHelp.ControlTipText, vbInformation, "Calendar help"
End Sub
 
A

Alimbilo

To call the Calendar on my form, I have added a Command Button that I named
"Calendarb".
And the date text box name on the form is "MyDate" which is bound to "Date"
field in a table.

So If I understand you answers, the code will be:
Me.Filter = "[Date] = #" & Me.Calendarb & "#"
Me.FilterOn = True

Right?

Thanks.




Klatuu said:
The filtering code does not go in the calendar form. It goes in the control
on your form where you call the calander. It returns the value to your form,
then you use the After Update event of the control on your form.
--
Dave Hargis, Microsoft Access MVP


Alimbilo said:
This is how the all concept is.
I have download the Calendar DB from an MVP website. and they have given
instruction hoe to configure it on your own website.

That Calendar has 2 part:
1. a module:
Option Compare Database
Option Explicit

'Calendar form variable:
Public gtxtCalTarget As TextBox 'Text box to return the date from the
calendar to.

Public Function CalendarFor(txt As TextBox, Optional strTitle As String)
'On Error GoTo Err_Handler
'Purpose: Open the calendar form, identifying the text box to return
the date to.
'Arguments: txt = the text box to return the date to.
' strTitle = the caption for the calendar form (passed in
OpenArgs).

Set gtxtCalTarget = txt
DoCmd.OpenForm "frmCalendar", windowmode:=acDialog, OpenArgs:=strTitle

Exit_Handler:
Exit Function

Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description, vbExclamation,
"CalendarFor()"
Resume Exit_Handler
End Function

Public Function LogError(lngErr As Long, strDescrip As String, strProc As
String, _
Optional bShowUser As Boolean = True, Optional varParam As Variant)
'Purpose: Minimal substitute for the real error logger function at:
' http://allenbrowne.com/ser-23a.html

If bShowUser Then
MsgBox "Error " & lngErr & ": " & strDescrip, vbExclamation, strProc
End If
End Function


And a Form which contains this code:

'Copyright: Allen Browne's Database And Training, 2007.
'Author: Allen Browne. (e-mail address removed)
Option Compare Database
Option Explicit

Private Const conMod = "frmCalendar"

Private Sub cmdCancel_Click()
On Error GoTo Err_Handler
'Purpose: Close without transferring date back to calling text box.

DoCmd.Close acForm, Me.Name, acSaveNo

Exit_Handler:
Exit Sub

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".cmdCancel_Click")
Resume Exit_Handler
End Sub

Private Sub cmdMonthDown_Click()
Call SetDate("M", -1)
End Sub
Private Sub cmdMonthUp_Click()
Call SetDate("M", 1)
End Sub

Private Sub cmdOk_Click()
On Error Resume Next
'Purpose: Transfer the result back to the calling text box (if there
is one), and close.

If Me.cmdOk.Enabled Then
If gtxtCalTarget = Me.txtDate Then
'do nothing
Else
gtxtCalTarget = Me.txtDate
End If
End If
gtxtCalTarget.SetFocus
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub

Private Sub cmdToday_Click()
'On Error GoTo Err_Handler
'Purpose: Set today.

Me.txtDate = Date
Call ShowCal

Exit_Handler:
Exit Sub

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".cmdToday_Click")
Resume Exit_Handler
End Sub

Private Sub cmdYearDown_Click()
Call SetDate("YYYY", -1)
End Sub
Private Sub cmdYearUp_Click()
Call SetDate("YYYY", 1)
End Sub

Private Sub Form_AfterUpdate()
Me.Filter = "[Date] = #" & Me.Calendar & "#"
Me.FilterOn = True
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'On Error GoTo Err_Handler
'Purpose:

With Me.txtDate
Select Case KeyCode
Case vbKeyLeft '1 day left or right.
.Value = .Value - 1
KeyCode = 0
Call ShowCal
Case vbKeyRight
.Value = .Value + 1
KeyCode = 0
Call ShowCal
Case vbKeyUp '1 week up or down.
.Value = .Value - 7
KeyCode = 0
Call ShowCal
Case vbKeyDown
.Value = .Value + 7
KeyCode = 0
Call ShowCal
Case vbKeyHome 'Home/End = first/last of this month.
.Value = .Value - Day(.Value) + 1
KeyCode = 0
Call ShowCal
Case vbKeyEnd
.Value = DateSerial(Year(.Value), Month(.Value) + 1, 0)
KeyCode = 0
Call ShowCal
Case vbKeyPageUp 'PgUp/PgDn = previous/next month.
.Value = DateAdd("m", -1, .Value)
KeyCode = 0
Call ShowCal
Case vbKeyPageDown
.Value = DateAdd("m", 1, .Value)
KeyCode = 0
Call ShowCal
Case vbKeyT, vbKeyT + 32 'T or t = today
.Value = Date
KeyCode = 0
Call ShowCal
End Select
End With

Exit_Handler:
Exit Sub

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".Form_KeyDown")
Resume Exit_Handler
End Sub

Private Sub Form_Open(Cancel As Integer)
'On Error GoTo Form_Open_Err
Dim bEnabled As Boolean

'Initialize to the existing date, or today if null.
If IsDate(gtxtCalTarget) Then
Me.txtDate = gtxtCalTarget.Value
Else
Me.txtDate = Date
End If

'Lock the Ok button if the text box is locked or disabled.
bEnabled = (gtxtCalTarget.Enabled) And (Not gtxtCalTarget.Locked)
With Me.cmdOk
If .Enabled <> bEnabled Then
.Enabled = bEnabled
End If
End With

'Set the title
If Len(Me.OpenArgs) > 0& Then
Me.Caption = Me.OpenArgs
End If

'Set up the calendar for this month.
Call ShowCal

Form_Open_Exit:
Exit Sub

Form_Open_Err:
MsgBox Err.Description, vbCritical, "frmCalendar.Form_Open"
Resume Form_Open_Exit
End Sub

Private Function SetSelected(ctlName As String)
On Error GoTo Err_Handler

Me.txtDate = DateSerial(Year(txtDate), Month(txtDate),
CLng(Me(ctlName).Caption))
Call ShowHighligher(ctlName)

Exit_Handler:
Exit Function

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".SetSelected")
Resume Exit_Handler
End Function

Private Function SelectDate(ctlName As String)
Call SetSelected(ctlName)
Call cmdOk_Click
End Function

Private Function SetDate(Subject As String, Optional intStep As Integer = 1)
On Error GoTo Err_Handler

Me.txtDate = DateAdd(Subject, intStep, Me.txtDate)
Call ShowCal

Exit_Handler:
Exit Function

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".SetDate")
Resume Exit_Handler
End Function

Private Function ShowCal() As Boolean
On Error GoTo Err_Handler
'Purpose:
Dim dtStartDate As Date 'First of month
Dim iDays As Integer 'Days in month
Dim iOffset As Integer 'Offset to first label for month.
Dim i As Integer 'Loop controller.
Dim iDay As Integer 'Day under consideration.
Dim bShow As Boolean 'Flag: show label

dtStartDate = Me.txtDate - Day(Me.txtDate) + 1 'First of month
iDays = Day(DateAdd("m", 1, dtStartDate) - 1) 'Days in month.
iOffset = Weekday(dtStartDate, vbSunday) - 2 'Offset to first label
for month.

For i = 0 To 41
With Me("lblDay" & Format(i, "00"))
iDay = i - iOffset
bShow = ((iDay > 0) And (iDay <= iDays))
If .Visible <> bShow Then
.Visible = bShow
End If
If (bShow) And (.Caption <> iDay) Then
.Caption = iDay
End If
End With
Next

Call ShowHighligher("lblDay" & Format(Day(Me.txtDate) + iOffset, "00"))

Exit_Handler:
Exit Function

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".ShowCal")
Resume Exit_Handler
End Function

Private Function ShowHighligher(ctlName As String)
On Error GoTo Err_Handler
Const lngcVOffset As Long = -83

With Me(ctlName)
Me.lblHighlight.Left = .Left
Me.lblHighlight.Top = .Top + lngcVOffset
End With

Exit_Handler:
Exit Function

Err_Handler:
 
D

Douglas J. Steele

<picky>

Not all users live in the US. Many may have their Short Date format set to
dd/mm/yyyy, so setting the filter that way can be dangerous.

Far safer is

Me.Filter = "[NameOfDateField] = " & Format(Me.DateControl,
"\#yyyy\-mm\-dd\#")

</picky>


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Klatuu said:
Me.Filter = "[NameOfDateField] = #" & Me.DateControl & "#"
Me.FilterOn = True

[NameOfDateField] would be the name of the field in the form's record
source
you want to filter on and Me.DateControl would be the name of the control
you
enter the date in. It would be in the After Update event of that control.
--
Dave Hargis, Microsoft Access MVP


Alimbilo said:
Yes, I am.
How do I set the Form Filter and Filterons properties?
And in the After Update event, what should I put in there.
 
A

Alimbilo

Thanks for the details but that didn't answer my previous question:

To call the Calendar on my form, I have added a Command Button that I named
"Calendarb".
And the date text box name on the form is "MyDate" which is bound to "Date"
field in a table.

So If I understand you answers, the code will be:
Me.Filter = "[Date] = #" & Me.Calendarb & "#"
Me.FilterOn = True

Right?

Thanks.


Douglas J. Steele said:
<picky>

Not all users live in the US. Many may have their Short Date format set to
dd/mm/yyyy, so setting the filter that way can be dangerous.

Far safer is

Me.Filter = "[NameOfDateField] = " & Format(Me.DateControl,
"\#yyyy\-mm\-dd\#")

</picky>


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Klatuu said:
Me.Filter = "[NameOfDateField] = #" & Me.DateControl & "#"
Me.FilterOn = True

[NameOfDateField] would be the name of the field in the form's record
source
you want to filter on and Me.DateControl would be the name of the control
you
enter the date in. It would be in the After Update event of that control.
--
Dave Hargis, Microsoft Access MVP


Alimbilo said:
Yes, I am.
How do I set the Form Filter and Filterons properties?
And in the After Update event, what should I put in there.


:

Are you saying you want to choose a date and have your form only show
records
that have a date field that is equal to the date you choose?

If so, use the After Update event of the control where you choose the
date
to set the form's Filter and Filteron properties.
--
Dave Hargis, Microsoft Access MVP


:

Ok.
The Date is a bound control.
What I am trying to do is whenever I click on the Date I choose in
the
calendar, I want all the fields value to be the records that I have
put on
that day.

Right now, I have a popup calendar but It doesn't really do what I
want. I
click on the date but nothing change in the fields.

Hope you understand me. Thanks

:

Well, there isn't enough information in your post to give you an
exact
answer. It really depends on whether the control you want to show
the date
in is a bound or unbound control. It also depends on whether you
are opening
the form in edit or add mode.
A more detailed description would be useful.
--
Dave Hargis, Microsoft Access MVP


:

How can I have a form to show the actual date as soon as it open
and have the
data empty ready for input?

I tried "On Current" but it doesn't let me move back to a
previous date.

Thanks.
 
K

Klatuu

I don't think so. Since you are calling the calander control from a command
button, the calander form can't return a value to a command button. You
should be calling the calander from the date control, but that control should
no be a bound control.
--
Dave Hargis, Microsoft Access MVP


Alimbilo said:
To call the Calendar on my form, I have added a Command Button that I named
"Calendarb".
And the date text box name on the form is "MyDate" which is bound to "Date"
field in a table.

So If I understand you answers, the code will be:
Me.Filter = "[Date] = #" & Me.Calendarb & "#"
Me.FilterOn = True

Right?

Thanks.




Klatuu said:
The filtering code does not go in the calendar form. It goes in the control
on your form where you call the calander. It returns the value to your form,
then you use the After Update event of the control on your form.
--
Dave Hargis, Microsoft Access MVP


Alimbilo said:
This is how the all concept is.
I have download the Calendar DB from an MVP website. and they have given
instruction hoe to configure it on your own website.

That Calendar has 2 part:
1. a module:
Option Compare Database
Option Explicit

'Calendar form variable:
Public gtxtCalTarget As TextBox 'Text box to return the date from the
calendar to.

Public Function CalendarFor(txt As TextBox, Optional strTitle As String)
'On Error GoTo Err_Handler
'Purpose: Open the calendar form, identifying the text box to return
the date to.
'Arguments: txt = the text box to return the date to.
' strTitle = the caption for the calendar form (passed in
OpenArgs).

Set gtxtCalTarget = txt
DoCmd.OpenForm "frmCalendar", windowmode:=acDialog, OpenArgs:=strTitle

Exit_Handler:
Exit Function

Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description, vbExclamation,
"CalendarFor()"
Resume Exit_Handler
End Function

Public Function LogError(lngErr As Long, strDescrip As String, strProc As
String, _
Optional bShowUser As Boolean = True, Optional varParam As Variant)
'Purpose: Minimal substitute for the real error logger function at:
' http://allenbrowne.com/ser-23a.html

If bShowUser Then
MsgBox "Error " & lngErr & ": " & strDescrip, vbExclamation, strProc
End If
End Function


And a Form which contains this code:

'Copyright: Allen Browne's Database And Training, 2007.
'Author: Allen Browne. (e-mail address removed)
Option Compare Database
Option Explicit

Private Const conMod = "frmCalendar"

Private Sub cmdCancel_Click()
On Error GoTo Err_Handler
'Purpose: Close without transferring date back to calling text box.

DoCmd.Close acForm, Me.Name, acSaveNo

Exit_Handler:
Exit Sub

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".cmdCancel_Click")
Resume Exit_Handler
End Sub

Private Sub cmdMonthDown_Click()
Call SetDate("M", -1)
End Sub
Private Sub cmdMonthUp_Click()
Call SetDate("M", 1)
End Sub

Private Sub cmdOk_Click()
On Error Resume Next
'Purpose: Transfer the result back to the calling text box (if there
is one), and close.

If Me.cmdOk.Enabled Then
If gtxtCalTarget = Me.txtDate Then
'do nothing
Else
gtxtCalTarget = Me.txtDate
End If
End If
gtxtCalTarget.SetFocus
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub

Private Sub cmdToday_Click()
'On Error GoTo Err_Handler
'Purpose: Set today.

Me.txtDate = Date
Call ShowCal

Exit_Handler:
Exit Sub

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".cmdToday_Click")
Resume Exit_Handler
End Sub

Private Sub cmdYearDown_Click()
Call SetDate("YYYY", -1)
End Sub
Private Sub cmdYearUp_Click()
Call SetDate("YYYY", 1)
End Sub

Private Sub Form_AfterUpdate()
Me.Filter = "[Date] = #" & Me.Calendar & "#"
Me.FilterOn = True
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'On Error GoTo Err_Handler
'Purpose:

With Me.txtDate
Select Case KeyCode
Case vbKeyLeft '1 day left or right.
.Value = .Value - 1
KeyCode = 0
Call ShowCal
Case vbKeyRight
.Value = .Value + 1
KeyCode = 0
Call ShowCal
Case vbKeyUp '1 week up or down.
.Value = .Value - 7
KeyCode = 0
Call ShowCal
Case vbKeyDown
.Value = .Value + 7
KeyCode = 0
Call ShowCal
Case vbKeyHome 'Home/End = first/last of this month.
.Value = .Value - Day(.Value) + 1
KeyCode = 0
Call ShowCal
Case vbKeyEnd
.Value = DateSerial(Year(.Value), Month(.Value) + 1, 0)
KeyCode = 0
Call ShowCal
Case vbKeyPageUp 'PgUp/PgDn = previous/next month.
.Value = DateAdd("m", -1, .Value)
KeyCode = 0
Call ShowCal
Case vbKeyPageDown
.Value = DateAdd("m", 1, .Value)
KeyCode = 0
Call ShowCal
Case vbKeyT, vbKeyT + 32 'T or t = today
.Value = Date
KeyCode = 0
Call ShowCal
End Select
End With

Exit_Handler:
Exit Sub

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".Form_KeyDown")
Resume Exit_Handler
End Sub

Private Sub Form_Open(Cancel As Integer)
'On Error GoTo Form_Open_Err
Dim bEnabled As Boolean

'Initialize to the existing date, or today if null.
If IsDate(gtxtCalTarget) Then
Me.txtDate = gtxtCalTarget.Value
Else
Me.txtDate = Date
End If

'Lock the Ok button if the text box is locked or disabled.
bEnabled = (gtxtCalTarget.Enabled) And (Not gtxtCalTarget.Locked)
With Me.cmdOk
If .Enabled <> bEnabled Then
.Enabled = bEnabled
End If
End With

'Set the title
If Len(Me.OpenArgs) > 0& Then
Me.Caption = Me.OpenArgs
End If

'Set up the calendar for this month.
Call ShowCal

Form_Open_Exit:
Exit Sub

Form_Open_Err:
MsgBox Err.Description, vbCritical, "frmCalendar.Form_Open"
Resume Form_Open_Exit
End Sub

Private Function SetSelected(ctlName As String)
On Error GoTo Err_Handler

Me.txtDate = DateSerial(Year(txtDate), Month(txtDate),
CLng(Me(ctlName).Caption))
Call ShowHighligher(ctlName)

Exit_Handler:
Exit Function

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".SetSelected")
Resume Exit_Handler
End Function

Private Function SelectDate(ctlName As String)
Call SetSelected(ctlName)
Call cmdOk_Click
End Function

Private Function SetDate(Subject As String, Optional intStep As Integer = 1)
On Error GoTo Err_Handler

Me.txtDate = DateAdd(Subject, intStep, Me.txtDate)
Call ShowCal

Exit_Handler:
Exit Function

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".SetDate")
Resume Exit_Handler
End Function

Private Function ShowCal() As Boolean
On Error GoTo Err_Handler
'Purpose:
Dim dtStartDate As Date 'First of month
Dim iDays As Integer 'Days in month
Dim iOffset As Integer 'Offset to first label for month.
Dim i As Integer 'Loop controller.
Dim iDay As Integer 'Day under consideration.
Dim bShow As Boolean 'Flag: show label

dtStartDate = Me.txtDate - Day(Me.txtDate) + 1 'First of month
iDays = Day(DateAdd("m", 1, dtStartDate) - 1) 'Days in month.
iOffset = Weekday(dtStartDate, vbSunday) - 2 'Offset to first label
for month.

For i = 0 To 41
With Me("lblDay" & Format(i, "00"))
iDay = i - iOffset
bShow = ((iDay > 0) And (iDay <= iDays))
If .Visible <> bShow Then
.Visible = bShow
End If
If (bShow) And (.Caption <> iDay) Then
.Caption = iDay
End If
End With
Next

Call ShowHighligher("lblDay" & Format(Day(Me.txtDate) + iOffset, "00"))

Exit_Handler:
Exit Function
 
A

Alimbilo

I just added an unbound control that I name "Calendarb" and called the
calendar from it which is worked perfect but the Filter doesn't work. I am
still having the same value even I change the date.

Me.Filter = "[NameOfDateField] = #" & Me.DateControl & "#"
Me.FilterOn = True

NameOfDateField = Date (I guess that the table field)
DateControl = calendarb

But the filter doesn't work.

Any other ideas?

Hope I am not asking too much. I am just trying to get help.

Thanks.

Klatuu said:
I don't think so. Since you are calling the calander control from a command
button, the calander form can't return a value to a command button. You
should be calling the calander from the date control, but that control should
no be a bound control.
--
Dave Hargis, Microsoft Access MVP


Alimbilo said:
To call the Calendar on my form, I have added a Command Button that I named
"Calendarb".
And the date text box name on the form is "MyDate" which is bound to "Date"
field in a table.

So If I understand you answers, the code will be:
Me.Filter = "[Date] = #" & Me.Calendarb & "#"
Me.FilterOn = True

Right?

Thanks.




Klatuu said:
The filtering code does not go in the calendar form. It goes in the control
on your form where you call the calander. It returns the value to your form,
then you use the After Update event of the control on your form.
--
Dave Hargis, Microsoft Access MVP


:

This is how the all concept is.
I have download the Calendar DB from an MVP website. and they have given
instruction hoe to configure it on your own website.

That Calendar has 2 part:
1. a module:
Option Compare Database
Option Explicit

'Calendar form variable:
Public gtxtCalTarget As TextBox 'Text box to return the date from the
calendar to.

Public Function CalendarFor(txt As TextBox, Optional strTitle As String)
'On Error GoTo Err_Handler
'Purpose: Open the calendar form, identifying the text box to return
the date to.
'Arguments: txt = the text box to return the date to.
' strTitle = the caption for the calendar form (passed in
OpenArgs).

Set gtxtCalTarget = txt
DoCmd.OpenForm "frmCalendar", windowmode:=acDialog, OpenArgs:=strTitle

Exit_Handler:
Exit Function

Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description, vbExclamation,
"CalendarFor()"
Resume Exit_Handler
End Function

Public Function LogError(lngErr As Long, strDescrip As String, strProc As
String, _
Optional bShowUser As Boolean = True, Optional varParam As Variant)
'Purpose: Minimal substitute for the real error logger function at:
' http://allenbrowne.com/ser-23a.html

If bShowUser Then
MsgBox "Error " & lngErr & ": " & strDescrip, vbExclamation, strProc
End If
End Function


And a Form which contains this code:

'Copyright: Allen Browne's Database And Training, 2007.
'Author: Allen Browne. (e-mail address removed)
Option Compare Database
Option Explicit

Private Const conMod = "frmCalendar"

Private Sub cmdCancel_Click()
On Error GoTo Err_Handler
'Purpose: Close without transferring date back to calling text box.

DoCmd.Close acForm, Me.Name, acSaveNo

Exit_Handler:
Exit Sub

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".cmdCancel_Click")
Resume Exit_Handler
End Sub

Private Sub cmdMonthDown_Click()
Call SetDate("M", -1)
End Sub
Private Sub cmdMonthUp_Click()
Call SetDate("M", 1)
End Sub

Private Sub cmdOk_Click()
On Error Resume Next
'Purpose: Transfer the result back to the calling text box (if there
is one), and close.

If Me.cmdOk.Enabled Then
If gtxtCalTarget = Me.txtDate Then
'do nothing
Else
gtxtCalTarget = Me.txtDate
End If
End If
gtxtCalTarget.SetFocus
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub

Private Sub cmdToday_Click()
'On Error GoTo Err_Handler
'Purpose: Set today.

Me.txtDate = Date
Call ShowCal

Exit_Handler:
Exit Sub

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".cmdToday_Click")
Resume Exit_Handler
End Sub

Private Sub cmdYearDown_Click()
Call SetDate("YYYY", -1)
End Sub
Private Sub cmdYearUp_Click()
Call SetDate("YYYY", 1)
End Sub

Private Sub Form_AfterUpdate()
Me.Filter = "[Date] = #" & Me.Calendar & "#"
Me.FilterOn = True
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'On Error GoTo Err_Handler
'Purpose:

With Me.txtDate
Select Case KeyCode
Case vbKeyLeft '1 day left or right.
.Value = .Value - 1
KeyCode = 0
Call ShowCal
Case vbKeyRight
.Value = .Value + 1
KeyCode = 0
Call ShowCal
Case vbKeyUp '1 week up or down.
.Value = .Value - 7
KeyCode = 0
Call ShowCal
Case vbKeyDown
.Value = .Value + 7
KeyCode = 0
Call ShowCal
Case vbKeyHome 'Home/End = first/last of this month.
.Value = .Value - Day(.Value) + 1
KeyCode = 0
Call ShowCal
Case vbKeyEnd
.Value = DateSerial(Year(.Value), Month(.Value) + 1, 0)
KeyCode = 0
Call ShowCal
Case vbKeyPageUp 'PgUp/PgDn = previous/next month.
.Value = DateAdd("m", -1, .Value)
KeyCode = 0
Call ShowCal
Case vbKeyPageDown
.Value = DateAdd("m", 1, .Value)
KeyCode = 0
Call ShowCal
Case vbKeyT, vbKeyT + 32 'T or t = today
.Value = Date
KeyCode = 0
Call ShowCal
End Select
End With

Exit_Handler:
Exit Sub

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".Form_KeyDown")
Resume Exit_Handler
End Sub

Private Sub Form_Open(Cancel As Integer)
'On Error GoTo Form_Open_Err
Dim bEnabled As Boolean

'Initialize to the existing date, or today if null.
If IsDate(gtxtCalTarget) Then
Me.txtDate = gtxtCalTarget.Value
Else
Me.txtDate = Date
End If

'Lock the Ok button if the text box is locked or disabled.
bEnabled = (gtxtCalTarget.Enabled) And (Not gtxtCalTarget.Locked)
With Me.cmdOk
If .Enabled <> bEnabled Then
.Enabled = bEnabled
End If
End With

'Set the title
If Len(Me.OpenArgs) > 0& Then
Me.Caption = Me.OpenArgs
End If

'Set up the calendar for this month.
Call ShowCal

Form_Open_Exit:
Exit Sub

Form_Open_Err:
MsgBox Err.Description, vbCritical, "frmCalendar.Form_Open"
Resume Form_Open_Exit
End Sub

Private Function SetSelected(ctlName As String)
On Error GoTo Err_Handler

Me.txtDate = DateSerial(Year(txtDate), Month(txtDate),
CLng(Me(ctlName).Caption))
Call ShowHighligher(ctlName)

Exit_Handler:
Exit Function

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".SetSelected")
Resume Exit_Handler
End Function

Private Function SelectDate(ctlName As String)
Call SetSelected(ctlName)
Call cmdOk_Click
End Function

Private Function SetDate(Subject As String, Optional intStep As Integer = 1)
On Error GoTo Err_Handler

Me.txtDate = DateAdd(Subject, intStep, Me.txtDate)
Call ShowCal

Exit_Handler:
Exit Function

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".SetDate")
Resume Exit_Handler
End Function

Private Function ShowCal() As Boolean
On Error GoTo Err_Handler
'Purpose:
Dim dtStartDate As Date 'First of month
Dim iDays As Integer 'Days in month
Dim iOffset As Integer 'Offset to first label for month.
Dim i As Integer 'Loop controller.
Dim iDay As Integer 'Day under consideration.
Dim bShow As Boolean 'Flag: show label

dtStartDate = Me.txtDate - Day(Me.txtDate) + 1 'First of month
iDays = Day(DateAdd("m", 1, dtStartDate) - 1) 'Days in month.
iOffset = Weekday(dtStartDate, vbSunday) - 2 'Offset to first label
for month.

For i = 0 To 41
With Me("lblDay" & Format(i, "00"))
iDay = i - iOffset
bShow = ((iDay > 0) And (iDay <= iDays))
If .Visible <> bShow Then
.Visible = bShow
End If
If (bShow) And (.Caption <> iDay) Then
 
K

Klatuu

I am going to have to download that control and see how it works before I can
give you a good answer. I'll get back to you shortly.
--
Dave Hargis, Microsoft Access MVP


Alimbilo said:
I just added an unbound control that I name "Calendarb" and called the
calendar from it which is worked perfect but the Filter doesn't work. I am
still having the same value even I change the date.

Me.Filter = "[NameOfDateField] = #" & Me.DateControl & "#"
Me.FilterOn = True

NameOfDateField = Date (I guess that the table field)
DateControl = calendarb

But the filter doesn't work.

Any other ideas?

Hope I am not asking too much. I am just trying to get help.

Thanks.

Klatuu said:
I don't think so. Since you are calling the calander control from a command
button, the calander form can't return a value to a command button. You
should be calling the calander from the date control, but that control should
no be a bound control.
--
Dave Hargis, Microsoft Access MVP


Alimbilo said:
To call the Calendar on my form, I have added a Command Button that I named
"Calendarb".
And the date text box name on the form is "MyDate" which is bound to "Date"
field in a table.

So If I understand you answers, the code will be:
Me.Filter = "[Date] = #" & Me.Calendarb & "#"
Me.FilterOn = True

Right?

Thanks.




:

The filtering code does not go in the calendar form. It goes in the control
on your form where you call the calander. It returns the value to your form,
then you use the After Update event of the control on your form.
--
Dave Hargis, Microsoft Access MVP


:

This is how the all concept is.
I have download the Calendar DB from an MVP website. and they have given
instruction hoe to configure it on your own website.

That Calendar has 2 part:
1. a module:
Option Compare Database
Option Explicit

'Calendar form variable:
Public gtxtCalTarget As TextBox 'Text box to return the date from the
calendar to.

Public Function CalendarFor(txt As TextBox, Optional strTitle As String)
'On Error GoTo Err_Handler
'Purpose: Open the calendar form, identifying the text box to return
the date to.
'Arguments: txt = the text box to return the date to.
' strTitle = the caption for the calendar form (passed in
OpenArgs).

Set gtxtCalTarget = txt
DoCmd.OpenForm "frmCalendar", windowmode:=acDialog, OpenArgs:=strTitle

Exit_Handler:
Exit Function

Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description, vbExclamation,
"CalendarFor()"
Resume Exit_Handler
End Function

Public Function LogError(lngErr As Long, strDescrip As String, strProc As
String, _
Optional bShowUser As Boolean = True, Optional varParam As Variant)
'Purpose: Minimal substitute for the real error logger function at:
' http://allenbrowne.com/ser-23a.html

If bShowUser Then
MsgBox "Error " & lngErr & ": " & strDescrip, vbExclamation, strProc
End If
End Function


And a Form which contains this code:

'Copyright: Allen Browne's Database And Training, 2007.
'Author: Allen Browne. (e-mail address removed)
Option Compare Database
Option Explicit

Private Const conMod = "frmCalendar"

Private Sub cmdCancel_Click()
On Error GoTo Err_Handler
'Purpose: Close without transferring date back to calling text box.

DoCmd.Close acForm, Me.Name, acSaveNo

Exit_Handler:
Exit Sub

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".cmdCancel_Click")
Resume Exit_Handler
End Sub

Private Sub cmdMonthDown_Click()
Call SetDate("M", -1)
End Sub
Private Sub cmdMonthUp_Click()
Call SetDate("M", 1)
End Sub

Private Sub cmdOk_Click()
On Error Resume Next
'Purpose: Transfer the result back to the calling text box (if there
is one), and close.

If Me.cmdOk.Enabled Then
If gtxtCalTarget = Me.txtDate Then
'do nothing
Else
gtxtCalTarget = Me.txtDate
End If
End If
gtxtCalTarget.SetFocus
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub

Private Sub cmdToday_Click()
'On Error GoTo Err_Handler
'Purpose: Set today.

Me.txtDate = Date
Call ShowCal

Exit_Handler:
Exit Sub

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".cmdToday_Click")
Resume Exit_Handler
End Sub

Private Sub cmdYearDown_Click()
Call SetDate("YYYY", -1)
End Sub
Private Sub cmdYearUp_Click()
Call SetDate("YYYY", 1)
End Sub

Private Sub Form_AfterUpdate()
Me.Filter = "[Date] = #" & Me.Calendar & "#"
Me.FilterOn = True
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'On Error GoTo Err_Handler
'Purpose:

With Me.txtDate
Select Case KeyCode
Case vbKeyLeft '1 day left or right.
.Value = .Value - 1
KeyCode = 0
Call ShowCal
Case vbKeyRight
.Value = .Value + 1
KeyCode = 0
Call ShowCal
Case vbKeyUp '1 week up or down.
.Value = .Value - 7
KeyCode = 0
Call ShowCal
Case vbKeyDown
.Value = .Value + 7
KeyCode = 0
Call ShowCal
Case vbKeyHome 'Home/End = first/last of this month.
.Value = .Value - Day(.Value) + 1
KeyCode = 0
Call ShowCal
Case vbKeyEnd
.Value = DateSerial(Year(.Value), Month(.Value) + 1, 0)
KeyCode = 0
Call ShowCal
Case vbKeyPageUp 'PgUp/PgDn = previous/next month.
.Value = DateAdd("m", -1, .Value)
KeyCode = 0
Call ShowCal
Case vbKeyPageDown
.Value = DateAdd("m", 1, .Value)
KeyCode = 0
Call ShowCal
Case vbKeyT, vbKeyT + 32 'T or t = today
.Value = Date
KeyCode = 0
Call ShowCal
End Select
End With

Exit_Handler:
Exit Sub

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".Form_KeyDown")
Resume Exit_Handler
End Sub

Private Sub Form_Open(Cancel As Integer)
'On Error GoTo Form_Open_Err
Dim bEnabled As Boolean

'Initialize to the existing date, or today if null.
If IsDate(gtxtCalTarget) Then
Me.txtDate = gtxtCalTarget.Value
Else
Me.txtDate = Date
End If

'Lock the Ok button if the text box is locked or disabled.
bEnabled = (gtxtCalTarget.Enabled) And (Not gtxtCalTarget.Locked)
With Me.cmdOk
If .Enabled <> bEnabled Then
.Enabled = bEnabled
End If
End With

'Set the title
If Len(Me.OpenArgs) > 0& Then
Me.Caption = Me.OpenArgs
End If

'Set up the calendar for this month.
Call ShowCal

Form_Open_Exit:
Exit Sub

Form_Open_Err:
MsgBox Err.Description, vbCritical, "frmCalendar.Form_Open"
Resume Form_Open_Exit
End Sub

Private Function SetSelected(ctlName As String)
On Error GoTo Err_Handler

Me.txtDate = DateSerial(Year(txtDate), Month(txtDate),
CLng(Me(ctlName).Caption))
Call ShowHighligher(ctlName)

Exit_Handler:
Exit Function

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".SetSelected")
Resume Exit_Handler
End Function

Private Function SelectDate(ctlName As String)
Call SetSelected(ctlName)
Call cmdOk_Click
End Function

Private Function SetDate(Subject As String, Optional intStep As Integer = 1)
On Error GoTo Err_Handler

Me.txtDate = DateAdd(Subject, intStep, Me.txtDate)
Call ShowCal

Exit_Handler:
Exit Function

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".SetDate")
Resume Exit_Handler
End Function

Private Function ShowCal() As Boolean
On Error GoTo Err_Handler
'Purpose:
 
A

Alimbilo

Thanks.
The Calendar Form can be download at this MVP website:

http://allenbrowne.com/bin/calendar2k.zip

I am waiting for your help.


Klatuu said:
I am going to have to download that control and see how it works before I can
give you a good answer. I'll get back to you shortly.
--
Dave Hargis, Microsoft Access MVP


Alimbilo said:
I just added an unbound control that I name "Calendarb" and called the
calendar from it which is worked perfect but the Filter doesn't work. I am
still having the same value even I change the date.

Me.Filter = "[NameOfDateField] = #" & Me.DateControl & "#"
Me.FilterOn = True

NameOfDateField = Date (I guess that the table field)
DateControl = calendarb

But the filter doesn't work.

Any other ideas?

Hope I am not asking too much. I am just trying to get help.

Thanks.

Klatuu said:
I don't think so. Since you are calling the calander control from a command
button, the calander form can't return a value to a command button. You
should be calling the calander from the date control, but that control should
no be a bound control.
--
Dave Hargis, Microsoft Access MVP


:

To call the Calendar on my form, I have added a Command Button that I named
"Calendarb".
And the date text box name on the form is "MyDate" which is bound to "Date"
field in a table.

So If I understand you answers, the code will be:
Me.Filter = "[Date] = #" & Me.Calendarb & "#"
Me.FilterOn = True

Right?

Thanks.




:

The filtering code does not go in the calendar form. It goes in the control
on your form where you call the calander. It returns the value to your form,
then you use the After Update event of the control on your form.
--
Dave Hargis, Microsoft Access MVP


:

This is how the all concept is.
I have download the Calendar DB from an MVP website. and they have given
instruction hoe to configure it on your own website.

That Calendar has 2 part:
1. a module:
Option Compare Database
Option Explicit

'Calendar form variable:
Public gtxtCalTarget As TextBox 'Text box to return the date from the
calendar to.

Public Function CalendarFor(txt As TextBox, Optional strTitle As String)
'On Error GoTo Err_Handler
'Purpose: Open the calendar form, identifying the text box to return
the date to.
'Arguments: txt = the text box to return the date to.
' strTitle = the caption for the calendar form (passed in
OpenArgs).

Set gtxtCalTarget = txt
DoCmd.OpenForm "frmCalendar", windowmode:=acDialog, OpenArgs:=strTitle

Exit_Handler:
Exit Function

Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description, vbExclamation,
"CalendarFor()"
Resume Exit_Handler
End Function

Public Function LogError(lngErr As Long, strDescrip As String, strProc As
String, _
Optional bShowUser As Boolean = True, Optional varParam As Variant)
'Purpose: Minimal substitute for the real error logger function at:
' http://allenbrowne.com/ser-23a.html

If bShowUser Then
MsgBox "Error " & lngErr & ": " & strDescrip, vbExclamation, strProc
End If
End Function


And a Form which contains this code:

'Copyright: Allen Browne's Database And Training, 2007.
'Author: Allen Browne. (e-mail address removed)
Option Compare Database
Option Explicit

Private Const conMod = "frmCalendar"

Private Sub cmdCancel_Click()
On Error GoTo Err_Handler
'Purpose: Close without transferring date back to calling text box.

DoCmd.Close acForm, Me.Name, acSaveNo

Exit_Handler:
Exit Sub

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".cmdCancel_Click")
Resume Exit_Handler
End Sub

Private Sub cmdMonthDown_Click()
Call SetDate("M", -1)
End Sub
Private Sub cmdMonthUp_Click()
Call SetDate("M", 1)
End Sub

Private Sub cmdOk_Click()
On Error Resume Next
'Purpose: Transfer the result back to the calling text box (if there
is one), and close.

If Me.cmdOk.Enabled Then
If gtxtCalTarget = Me.txtDate Then
'do nothing
Else
gtxtCalTarget = Me.txtDate
End If
End If
gtxtCalTarget.SetFocus
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub

Private Sub cmdToday_Click()
'On Error GoTo Err_Handler
'Purpose: Set today.

Me.txtDate = Date
Call ShowCal

Exit_Handler:
Exit Sub

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".cmdToday_Click")
Resume Exit_Handler
End Sub

Private Sub cmdYearDown_Click()
Call SetDate("YYYY", -1)
End Sub
Private Sub cmdYearUp_Click()
Call SetDate("YYYY", 1)
End Sub

Private Sub Form_AfterUpdate()
Me.Filter = "[Date] = #" & Me.Calendar & "#"
Me.FilterOn = True
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'On Error GoTo Err_Handler
'Purpose:

With Me.txtDate
Select Case KeyCode
Case vbKeyLeft '1 day left or right.
.Value = .Value - 1
KeyCode = 0
Call ShowCal
Case vbKeyRight
.Value = .Value + 1
KeyCode = 0
Call ShowCal
Case vbKeyUp '1 week up or down.
.Value = .Value - 7
KeyCode = 0
Call ShowCal
Case vbKeyDown
.Value = .Value + 7
KeyCode = 0
Call ShowCal
Case vbKeyHome 'Home/End = first/last of this month.
.Value = .Value - Day(.Value) + 1
KeyCode = 0
Call ShowCal
Case vbKeyEnd
.Value = DateSerial(Year(.Value), Month(.Value) + 1, 0)
KeyCode = 0
Call ShowCal
Case vbKeyPageUp 'PgUp/PgDn = previous/next month.
.Value = DateAdd("m", -1, .Value)
KeyCode = 0
Call ShowCal
Case vbKeyPageDown
.Value = DateAdd("m", 1, .Value)
KeyCode = 0
Call ShowCal
Case vbKeyT, vbKeyT + 32 'T or t = today
.Value = Date
KeyCode = 0
Call ShowCal
End Select
End With

Exit_Handler:
Exit Sub

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".Form_KeyDown")
Resume Exit_Handler
End Sub

Private Sub Form_Open(Cancel As Integer)
'On Error GoTo Form_Open_Err
Dim bEnabled As Boolean

'Initialize to the existing date, or today if null.
If IsDate(gtxtCalTarget) Then
Me.txtDate = gtxtCalTarget.Value
Else
Me.txtDate = Date
End If

'Lock the Ok button if the text box is locked or disabled.
bEnabled = (gtxtCalTarget.Enabled) And (Not gtxtCalTarget.Locked)
With Me.cmdOk
If .Enabled <> bEnabled Then
.Enabled = bEnabled
End If
End With

'Set the title
If Len(Me.OpenArgs) > 0& Then
Me.Caption = Me.OpenArgs
End If

'Set up the calendar for this month.
Call ShowCal

Form_Open_Exit:
Exit Sub

Form_Open_Err:
MsgBox Err.Description, vbCritical, "frmCalendar.Form_Open"
Resume Form_Open_Exit
End Sub

Private Function SetSelected(ctlName As String)
On Error GoTo Err_Handler

Me.txtDate = DateSerial(Year(txtDate), Month(txtDate),
CLng(Me(ctlName).Caption))
Call ShowHighligher(ctlName)

Exit_Handler:
Exit Function

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".SetSelected")
Resume Exit_Handler
End Function

Private Function SelectDate(ctlName As String)
Call SetSelected(ctlName)
Call cmdOk_Click
End Function

Private Function SetDate(Subject As String, Optional intStep As Integer = 1)
On Error GoTo Err_Handler

Me.txtDate = DateAdd(Subject, intStep, Me.txtDate)
Call ShowCal

Exit_Handler:
Exit Function
 
K

Klatuu

Thanks, I already got it and looked at it.
If you follow the instructions on the sample (frmExample) form in that
database, it will show you exactly how to use it. I had no problem putting
it on a form in my test database at all.
--
Dave Hargis, Microsoft Access MVP


Alimbilo said:
Thanks.
The Calendar Form can be download at this MVP website:

http://allenbrowne.com/bin/calendar2k.zip

I am waiting for your help.


Klatuu said:
I am going to have to download that control and see how it works before I can
give you a good answer. I'll get back to you shortly.
--
Dave Hargis, Microsoft Access MVP


Alimbilo said:
I just added an unbound control that I name "Calendarb" and called the
calendar from it which is worked perfect but the Filter doesn't work. I am
still having the same value even I change the date.

Me.Filter = "[NameOfDateField] = #" & Me.DateControl & "#"
Me.FilterOn = True

NameOfDateField = Date (I guess that the table field)
DateControl = calendarb

But the filter doesn't work.

Any other ideas?

Hope I am not asking too much. I am just trying to get help.

Thanks.

:

I don't think so. Since you are calling the calander control from a command
button, the calander form can't return a value to a command button. You
should be calling the calander from the date control, but that control should
no be a bound control.
--
Dave Hargis, Microsoft Access MVP


:

To call the Calendar on my form, I have added a Command Button that I named
"Calendarb".
And the date text box name on the form is "MyDate" which is bound to "Date"
field in a table.

So If I understand you answers, the code will be:
Me.Filter = "[Date] = #" & Me.Calendarb & "#"
Me.FilterOn = True

Right?

Thanks.




:

The filtering code does not go in the calendar form. It goes in the control
on your form where you call the calander. It returns the value to your form,
then you use the After Update event of the control on your form.
--
Dave Hargis, Microsoft Access MVP


:

This is how the all concept is.
I have download the Calendar DB from an MVP website. and they have given
instruction hoe to configure it on your own website.

That Calendar has 2 part:
1. a module:
Option Compare Database
Option Explicit

'Calendar form variable:
Public gtxtCalTarget As TextBox 'Text box to return the date from the
calendar to.

Public Function CalendarFor(txt As TextBox, Optional strTitle As String)
'On Error GoTo Err_Handler
'Purpose: Open the calendar form, identifying the text box to return
the date to.
'Arguments: txt = the text box to return the date to.
' strTitle = the caption for the calendar form (passed in
OpenArgs).

Set gtxtCalTarget = txt
DoCmd.OpenForm "frmCalendar", windowmode:=acDialog, OpenArgs:=strTitle

Exit_Handler:
Exit Function

Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description, vbExclamation,
"CalendarFor()"
Resume Exit_Handler
End Function

Public Function LogError(lngErr As Long, strDescrip As String, strProc As
String, _
Optional bShowUser As Boolean = True, Optional varParam As Variant)
'Purpose: Minimal substitute for the real error logger function at:
' http://allenbrowne.com/ser-23a.html

If bShowUser Then
MsgBox "Error " & lngErr & ": " & strDescrip, vbExclamation, strProc
End If
End Function


And a Form which contains this code:

'Copyright: Allen Browne's Database And Training, 2007.
'Author: Allen Browne. (e-mail address removed)
Option Compare Database
Option Explicit

Private Const conMod = "frmCalendar"

Private Sub cmdCancel_Click()
On Error GoTo Err_Handler
'Purpose: Close without transferring date back to calling text box.

DoCmd.Close acForm, Me.Name, acSaveNo

Exit_Handler:
Exit Sub

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".cmdCancel_Click")
Resume Exit_Handler
End Sub

Private Sub cmdMonthDown_Click()
Call SetDate("M", -1)
End Sub
Private Sub cmdMonthUp_Click()
Call SetDate("M", 1)
End Sub

Private Sub cmdOk_Click()
On Error Resume Next
'Purpose: Transfer the result back to the calling text box (if there
is one), and close.

If Me.cmdOk.Enabled Then
If gtxtCalTarget = Me.txtDate Then
'do nothing
Else
gtxtCalTarget = Me.txtDate
End If
End If
gtxtCalTarget.SetFocus
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub

Private Sub cmdToday_Click()
'On Error GoTo Err_Handler
'Purpose: Set today.

Me.txtDate = Date
Call ShowCal

Exit_Handler:
Exit Sub

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".cmdToday_Click")
Resume Exit_Handler
End Sub

Private Sub cmdYearDown_Click()
Call SetDate("YYYY", -1)
End Sub
Private Sub cmdYearUp_Click()
Call SetDate("YYYY", 1)
End Sub

Private Sub Form_AfterUpdate()
Me.Filter = "[Date] = #" & Me.Calendar & "#"
Me.FilterOn = True
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'On Error GoTo Err_Handler
'Purpose:

With Me.txtDate
Select Case KeyCode
Case vbKeyLeft '1 day left or right.
.Value = .Value - 1
KeyCode = 0
Call ShowCal
Case vbKeyRight
.Value = .Value + 1
KeyCode = 0
Call ShowCal
Case vbKeyUp '1 week up or down.
.Value = .Value - 7
KeyCode = 0
Call ShowCal
Case vbKeyDown
.Value = .Value + 7
KeyCode = 0
Call ShowCal
Case vbKeyHome 'Home/End = first/last of this month.
.Value = .Value - Day(.Value) + 1
KeyCode = 0
Call ShowCal
Case vbKeyEnd
.Value = DateSerial(Year(.Value), Month(.Value) + 1, 0)
KeyCode = 0
Call ShowCal
Case vbKeyPageUp 'PgUp/PgDn = previous/next month.
.Value = DateAdd("m", -1, .Value)
KeyCode = 0
Call ShowCal
Case vbKeyPageDown
.Value = DateAdd("m", 1, .Value)
KeyCode = 0
Call ShowCal
Case vbKeyT, vbKeyT + 32 'T or t = today
.Value = Date
KeyCode = 0
Call ShowCal
End Select
End With

Exit_Handler:
Exit Sub

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".Form_KeyDown")
Resume Exit_Handler
End Sub

Private Sub Form_Open(Cancel As Integer)
'On Error GoTo Form_Open_Err
Dim bEnabled As Boolean

'Initialize to the existing date, or today if null.
If IsDate(gtxtCalTarget) Then
Me.txtDate = gtxtCalTarget.Value
Else
Me.txtDate = Date
End If

'Lock the Ok button if the text box is locked or disabled.
bEnabled = (gtxtCalTarget.Enabled) And (Not gtxtCalTarget.Locked)
With Me.cmdOk
If .Enabled <> bEnabled Then
.Enabled = bEnabled
End If
End With

'Set the title
If Len(Me.OpenArgs) > 0& Then
Me.Caption = Me.OpenArgs
End If

'Set up the calendar for this month.
Call ShowCal

Form_Open_Exit:
Exit Sub

Form_Open_Err:
MsgBox Err.Description, vbCritical, "frmCalendar.Form_Open"
Resume Form_Open_Exit
End Sub

Private Function SetSelected(ctlName As String)
On Error GoTo Err_Handler

Me.txtDate = DateSerial(Year(txtDate), Month(txtDate),
CLng(Me(ctlName).Caption))
Call ShowHighligher(ctlName)

Exit_Handler:
Exit Function

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".SetSelected")
Resume Exit_Handler
End Function

Private Function SelectDate(ctlName As String)
Call SetSelected(ctlName)
Call cmdOk_Click
End Function
 
D

Douglas J. Steele

If the command button is name Calendarb, then you don't use Me.Calendarb in
the filter. You need to use the name of the calendar control.


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Alimbilo said:
Thanks for the details but that didn't answer my previous question:

To call the Calendar on my form, I have added a Command Button that I
named
"Calendarb".
And the date text box name on the form is "MyDate" which is bound to
"Date"
field in a table.

So If I understand you answers, the code will be:
Me.Filter = "[Date] = #" & Me.Calendarb & "#"
Me.FilterOn = True

Right?

Thanks.


Douglas J. Steele said:
<picky>

Not all users live in the US. Many may have their Short Date format set
to
dd/mm/yyyy, so setting the filter that way can be dangerous.

Far safer is

Me.Filter = "[NameOfDateField] = " & Format(Me.DateControl,
"\#yyyy\-mm\-dd\#")

</picky>


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Klatuu said:
Me.Filter = "[NameOfDateField] = #" & Me.DateControl & "#"
Me.FilterOn = True

[NameOfDateField] would be the name of the field in the form's record
source
you want to filter on and Me.DateControl would be the name of the
control
you
enter the date in. It would be in the After Update event of that
control.
--
Dave Hargis, Microsoft Access MVP


:

Yes, I am.
How do I set the Form Filter and Filterons properties?
And in the After Update event, what should I put in there.


:

Are you saying you want to choose a date and have your form only
show
records
that have a date field that is equal to the date you choose?

If so, use the After Update event of the control where you choose
the
date
to set the form's Filter and Filteron properties.
--
Dave Hargis, Microsoft Access MVP


:

Ok.
The Date is a bound control.
What I am trying to do is whenever I click on the Date I choose in
the
calendar, I want all the fields value to be the records that I
have
put on
that day.

Right now, I have a popup calendar but It doesn't really do what I
want. I
click on the date but nothing change in the fields.

Hope you understand me. Thanks

:

Well, there isn't enough information in your post to give you an
exact
answer. It really depends on whether the control you want to
show
the date
in is a bound or unbound control. It also depends on whether
you
are opening
the form in edit or add mode.
A more detailed description would be useful.
--
Dave Hargis, Microsoft Access MVP


:

How can I have a form to show the actual date as soon as it
open
and have the
data empty ready for input?

I tried "On Current" but it doesn't let me move back to a
previous date.

Thanks.
 
A

Alimbilo

I did all that and the Calendar is showing perfect. But the Filter doesn't
work when I pick a date on the calendar.

Me.Filter = "[NameOfDateField] = #" & Me.DateControl & "#"
Me.FilterOn = True
NameOfDateField = Date (I guess that the table field)
DateControl = calendarb

Am I having a problem because I am using a Join (relationship) table on the
form?



Klatuu said:
Thanks, I already got it and looked at it.
If you follow the instructions on the sample (frmExample) form in that
database, it will show you exactly how to use it. I had no problem putting
it on a form in my test database at all.
--
Dave Hargis, Microsoft Access MVP


Alimbilo said:
Thanks.
The Calendar Form can be download at this MVP website:

http://allenbrowne.com/bin/calendar2k.zip

I am waiting for your help.


Klatuu said:
I am going to have to download that control and see how it works before I can
give you a good answer. I'll get back to you shortly.
--
Dave Hargis, Microsoft Access MVP


:

I just added an unbound control that I name "Calendarb" and called the
calendar from it which is worked perfect but the Filter doesn't work. I am
still having the same value even I change the date.

Me.Filter = "[NameOfDateField] = #" & Me.DateControl & "#"
Me.FilterOn = True

NameOfDateField = Date (I guess that the table field)
DateControl = calendarb

But the filter doesn't work.

Any other ideas?

Hope I am not asking too much. I am just trying to get help.

Thanks.

:

I don't think so. Since you are calling the calander control from a command
button, the calander form can't return a value to a command button. You
should be calling the calander from the date control, but that control should
no be a bound control.
--
Dave Hargis, Microsoft Access MVP


:

To call the Calendar on my form, I have added a Command Button that I named
"Calendarb".
And the date text box name on the form is "MyDate" which is bound to "Date"
field in a table.

So If I understand you answers, the code will be:
Me.Filter = "[Date] = #" & Me.Calendarb & "#"
Me.FilterOn = True

Right?

Thanks.




:

The filtering code does not go in the calendar form. It goes in the control
on your form where you call the calander. It returns the value to your form,
then you use the After Update event of the control on your form.
--
Dave Hargis, Microsoft Access MVP


:

This is how the all concept is.
I have download the Calendar DB from an MVP website. and they have given
instruction hoe to configure it on your own website.

That Calendar has 2 part:
1. a module:
Option Compare Database
Option Explicit

'Calendar form variable:
Public gtxtCalTarget As TextBox 'Text box to return the date from the
calendar to.

Public Function CalendarFor(txt As TextBox, Optional strTitle As String)
'On Error GoTo Err_Handler
'Purpose: Open the calendar form, identifying the text box to return
the date to.
'Arguments: txt = the text box to return the date to.
' strTitle = the caption for the calendar form (passed in
OpenArgs).

Set gtxtCalTarget = txt
DoCmd.OpenForm "frmCalendar", windowmode:=acDialog, OpenArgs:=strTitle

Exit_Handler:
Exit Function

Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description, vbExclamation,
"CalendarFor()"
Resume Exit_Handler
End Function

Public Function LogError(lngErr As Long, strDescrip As String, strProc As
String, _
Optional bShowUser As Boolean = True, Optional varParam As Variant)
'Purpose: Minimal substitute for the real error logger function at:
' http://allenbrowne.com/ser-23a.html

If bShowUser Then
MsgBox "Error " & lngErr & ": " & strDescrip, vbExclamation, strProc
End If
End Function


And a Form which contains this code:

'Copyright: Allen Browne's Database And Training, 2007.
'Author: Allen Browne. (e-mail address removed)
Option Compare Database
Option Explicit

Private Const conMod = "frmCalendar"

Private Sub cmdCancel_Click()
On Error GoTo Err_Handler
'Purpose: Close without transferring date back to calling text box.

DoCmd.Close acForm, Me.Name, acSaveNo

Exit_Handler:
Exit Sub

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".cmdCancel_Click")
Resume Exit_Handler
End Sub

Private Sub cmdMonthDown_Click()
Call SetDate("M", -1)
End Sub
Private Sub cmdMonthUp_Click()
Call SetDate("M", 1)
End Sub

Private Sub cmdOk_Click()
On Error Resume Next
'Purpose: Transfer the result back to the calling text box (if there
is one), and close.

If Me.cmdOk.Enabled Then
If gtxtCalTarget = Me.txtDate Then
'do nothing
Else
gtxtCalTarget = Me.txtDate
End If
End If
gtxtCalTarget.SetFocus
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub

Private Sub cmdToday_Click()
'On Error GoTo Err_Handler
'Purpose: Set today.

Me.txtDate = Date
Call ShowCal

Exit_Handler:
Exit Sub

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".cmdToday_Click")
Resume Exit_Handler
End Sub

Private Sub cmdYearDown_Click()
Call SetDate("YYYY", -1)
End Sub
Private Sub cmdYearUp_Click()
Call SetDate("YYYY", 1)
End Sub

Private Sub Form_AfterUpdate()
Me.Filter = "[Date] = #" & Me.Calendar & "#"
Me.FilterOn = True
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'On Error GoTo Err_Handler
'Purpose:

With Me.txtDate
Select Case KeyCode
Case vbKeyLeft '1 day left or right.
.Value = .Value - 1
KeyCode = 0
Call ShowCal
Case vbKeyRight
.Value = .Value + 1
KeyCode = 0
Call ShowCal
Case vbKeyUp '1 week up or down.
.Value = .Value - 7
KeyCode = 0
Call ShowCal
Case vbKeyDown
.Value = .Value + 7
KeyCode = 0
Call ShowCal
Case vbKeyHome 'Home/End = first/last of this month.
.Value = .Value - Day(.Value) + 1
KeyCode = 0
Call ShowCal
Case vbKeyEnd
.Value = DateSerial(Year(.Value), Month(.Value) + 1, 0)
KeyCode = 0
Call ShowCal
Case vbKeyPageUp 'PgUp/PgDn = previous/next month.
.Value = DateAdd("m", -1, .Value)
KeyCode = 0
Call ShowCal
Case vbKeyPageDown
.Value = DateAdd("m", 1, .Value)
KeyCode = 0
Call ShowCal
Case vbKeyT, vbKeyT + 32 'T or t = today
.Value = Date
KeyCode = 0
Call ShowCal
End Select
End With

Exit_Handler:
Exit Sub

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".Form_KeyDown")
Resume Exit_Handler
End Sub

Private Sub Form_Open(Cancel As Integer)
'On Error GoTo Form_Open_Err
Dim bEnabled As Boolean

'Initialize to the existing date, or today if null.
If IsDate(gtxtCalTarget) Then
Me.txtDate = gtxtCalTarget.Value
Else
Me.txtDate = Date
End If

'Lock the Ok button if the text box is locked or disabled.
bEnabled = (gtxtCalTarget.Enabled) And (Not gtxtCalTarget.Locked)
With Me.cmdOk
If .Enabled <> bEnabled Then
.Enabled = bEnabled
End If
End With

'Set the title
If Len(Me.OpenArgs) > 0& Then
Me.Caption = Me.OpenArgs
End If

'Set up the calendar for this month.
Call ShowCal

Form_Open_Exit:
Exit Sub

Form_Open_Err:
MsgBox Err.Description, vbCritical, "frmCalendar.Form_Open"
Resume Form_Open_Exit
End Sub

Private Function SetSelected(ctlName As String)
On Error GoTo Err_Handler

Me.txtDate = DateSerial(Year(txtDate), Month(txtDate),
CLng(Me(ctlName).Caption))
Call ShowHighligher(ctlName)

Exit_Handler:
Exit Function
 
K

Klatuu

Okay, I understand the problem now.
The issue is that a control's After Update event does not fire if the
control is populated programmatically as it is in this case. It only fires
when a user types a value in the control.

So, one way to do it would be to modify the cmdOk_Click event in frmCalendar
to set the filter. The only thing wrong with that is that now the calendar
control can only be used for that specific form and control. Another way
would be to use the Lost Focus event of the command button that brings up the
calendar form, but then it will fire even if you didn't select a value from
the calendar. So, you will have to decide where you want to set the filter.
--
Dave Hargis, Microsoft Access MVP


Alimbilo said:
I did all that and the Calendar is showing perfect. But the Filter doesn't
work when I pick a date on the calendar.

Me.Filter = "[NameOfDateField] = #" & Me.DateControl & "#"
Me.FilterOn = True
NameOfDateField = Date (I guess that the table field)
DateControl = calendarb

Am I having a problem because I am using a Join (relationship) table on the
form?



Klatuu said:
Thanks, I already got it and looked at it.
If you follow the instructions on the sample (frmExample) form in that
database, it will show you exactly how to use it. I had no problem putting
it on a form in my test database at all.
--
Dave Hargis, Microsoft Access MVP


Alimbilo said:
Thanks.
The Calendar Form can be download at this MVP website:

http://allenbrowne.com/bin/calendar2k.zip

I am waiting for your help.


:

I am going to have to download that control and see how it works before I can
give you a good answer. I'll get back to you shortly.
--
Dave Hargis, Microsoft Access MVP


:

I just added an unbound control that I name "Calendarb" and called the
calendar from it which is worked perfect but the Filter doesn't work. I am
still having the same value even I change the date.

Me.Filter = "[NameOfDateField] = #" & Me.DateControl & "#"
Me.FilterOn = True

NameOfDateField = Date (I guess that the table field)
DateControl = calendarb

But the filter doesn't work.

Any other ideas?

Hope I am not asking too much. I am just trying to get help.

Thanks.

:

I don't think so. Since you are calling the calander control from a command
button, the calander form can't return a value to a command button. You
should be calling the calander from the date control, but that control should
no be a bound control.
--
Dave Hargis, Microsoft Access MVP


:

To call the Calendar on my form, I have added a Command Button that I named
"Calendarb".
And the date text box name on the form is "MyDate" which is bound to "Date"
field in a table.

So If I understand you answers, the code will be:
Me.Filter = "[Date] = #" & Me.Calendarb & "#"
Me.FilterOn = True

Right?

Thanks.




:

The filtering code does not go in the calendar form. It goes in the control
on your form where you call the calander. It returns the value to your form,
then you use the After Update event of the control on your form.
--
Dave Hargis, Microsoft Access MVP


:

This is how the all concept is.
I have download the Calendar DB from an MVP website. and they have given
instruction hoe to configure it on your own website.

That Calendar has 2 part:
1. a module:
Option Compare Database
Option Explicit

'Calendar form variable:
Public gtxtCalTarget As TextBox 'Text box to return the date from the
calendar to.

Public Function CalendarFor(txt As TextBox, Optional strTitle As String)
'On Error GoTo Err_Handler
'Purpose: Open the calendar form, identifying the text box to return
the date to.
'Arguments: txt = the text box to return the date to.
' strTitle = the caption for the calendar form (passed in
OpenArgs).

Set gtxtCalTarget = txt
DoCmd.OpenForm "frmCalendar", windowmode:=acDialog, OpenArgs:=strTitle

Exit_Handler:
Exit Function

Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description, vbExclamation,
"CalendarFor()"
Resume Exit_Handler
End Function

Public Function LogError(lngErr As Long, strDescrip As String, strProc As
String, _
Optional bShowUser As Boolean = True, Optional varParam As Variant)
'Purpose: Minimal substitute for the real error logger function at:
' http://allenbrowne.com/ser-23a.html

If bShowUser Then
MsgBox "Error " & lngErr & ": " & strDescrip, vbExclamation, strProc
End If
End Function


And a Form which contains this code:

'Copyright: Allen Browne's Database And Training, 2007.
'Author: Allen Browne. (e-mail address removed)
Option Compare Database
Option Explicit

Private Const conMod = "frmCalendar"

Private Sub cmdCancel_Click()
On Error GoTo Err_Handler
'Purpose: Close without transferring date back to calling text box.

DoCmd.Close acForm, Me.Name, acSaveNo

Exit_Handler:
Exit Sub

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".cmdCancel_Click")
Resume Exit_Handler
End Sub

Private Sub cmdMonthDown_Click()
Call SetDate("M", -1)
End Sub
Private Sub cmdMonthUp_Click()
Call SetDate("M", 1)
End Sub

Private Sub cmdOk_Click()
On Error Resume Next
'Purpose: Transfer the result back to the calling text box (if there
is one), and close.

If Me.cmdOk.Enabled Then
If gtxtCalTarget = Me.txtDate Then
'do nothing
Else
gtxtCalTarget = Me.txtDate
End If
End If
gtxtCalTarget.SetFocus
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub

Private Sub cmdToday_Click()
'On Error GoTo Err_Handler
'Purpose: Set today.

Me.txtDate = Date
Call ShowCal

Exit_Handler:
Exit Sub

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".cmdToday_Click")
Resume Exit_Handler
End Sub

Private Sub cmdYearDown_Click()
Call SetDate("YYYY", -1)
End Sub
Private Sub cmdYearUp_Click()
Call SetDate("YYYY", 1)
End Sub

Private Sub Form_AfterUpdate()
Me.Filter = "[Date] = #" & Me.Calendar & "#"
Me.FilterOn = True
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'On Error GoTo Err_Handler
'Purpose:

With Me.txtDate
Select Case KeyCode
Case vbKeyLeft '1 day left or right.
.Value = .Value - 1
KeyCode = 0
Call ShowCal
Case vbKeyRight
.Value = .Value + 1
KeyCode = 0
Call ShowCal
Case vbKeyUp '1 week up or down.
.Value = .Value - 7
KeyCode = 0
Call ShowCal
Case vbKeyDown
.Value = .Value + 7
KeyCode = 0
Call ShowCal
Case vbKeyHome 'Home/End = first/last of this month.
.Value = .Value - Day(.Value) + 1
KeyCode = 0
Call ShowCal
Case vbKeyEnd
.Value = DateSerial(Year(.Value), Month(.Value) + 1, 0)
KeyCode = 0
Call ShowCal
Case vbKeyPageUp 'PgUp/PgDn = previous/next month.
.Value = DateAdd("m", -1, .Value)
KeyCode = 0
Call ShowCal
Case vbKeyPageDown
.Value = DateAdd("m", 1, .Value)
KeyCode = 0
Call ShowCal
Case vbKeyT, vbKeyT + 32 'T or t = today
.Value = Date
KeyCode = 0
Call ShowCal
End Select
End With

Exit_Handler:
Exit Sub

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".Form_KeyDown")
Resume Exit_Handler
End Sub

Private Sub Form_Open(Cancel As Integer)
'On Error GoTo Form_Open_Err
Dim bEnabled As Boolean

'Initialize to the existing date, or today if null.
If IsDate(gtxtCalTarget) Then
Me.txtDate = gtxtCalTarget.Value
Else
Me.txtDate = Date
End If

'Lock the Ok button if the text box is locked or disabled.
bEnabled = (gtxtCalTarget.Enabled) And (Not gtxtCalTarget.Locked)
With Me.cmdOk
If .Enabled <> bEnabled Then
.Enabled = bEnabled
End If
End With

'Set the title
If Len(Me.OpenArgs) > 0& Then
Me.Caption = Me.OpenArgs
End If

'Set up the calendar for this month.
Call ShowCal

Form_Open_Exit:
Exit Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top