Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Range

Status
Not open for further replies.

ksimmsa

Programmer
Feb 6, 2004
22
US
I have a report in Access based off of a query that has a date range. I need to have the selected date range to appear at the header of the report.

Thanks in advance for you help.

 
this is the way i came up with doing this.

put this in a module:
Code:
Public varStartDate As Variant
Public varEndDate As Variant

Public Function getvarStartDate() As String
'hold Start Date
   getvarStartDate = varStartDate
End Function

Public Function getvarEndDate() As String
'hold Start Date
   getvarEndDate = varEndDate
End Function
----------------------------------------------------

add the code below to a form named frmCFMCriteria that has:
text box named txtStartDate
text box named txtEndDate
command button named cmdEnter
command button named cmdCancel
Code:
Private Sub cmdCancel_Click()
    DoCmd.Close acForm, "frmCFMCriteria"
End Sub

Private Sub cmdEnter_Click()
    varStartDate = Me.txtStartDate
    varEndDate = Me.txtEndDate
    DoCmd.OpenReport "CFM Log", acViewPreview
    DoCmd.Close acForm, "frmCFMCriteria"
End Sub

Private Sub Form_Load()
    Me.TimerInterval = 1
End Sub

Private Sub Form_Timer()
    Me.TimerInterval = 0
    DoCmd.Close acReport, "CFM Log"
End Sub
----------------------------------------------------

add this to the criteria of the date field:
Code:
Between getvarStartDate() And getvarEndDate()
----------------------------------------------------

then add a text box to the header of the report and add this as the control source:
Code:
="From " & getvarStartDate() & " through " & getvarEndDate()
----------------------------------------------------

add this code to the report:
Code:
Private Sub Report_Close()
    varStartDate = ""
    varEndDate = ""
End Sub

Private Sub Report_Open(Cancel As Integer)
    If varStartDate = "" Or varEndDate = "" Then
        DoCmd.OpenForm "frmCFMCriteria"
        Cancel = 1
        Exit Sub
    End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top