Button for Current Year

M

Mary

I'd like to add buttons for current year and previous year to a form. The
report is pulling all records. The field in the underlying query is DueDate,
the field on the report is DueD.

There is an if statement that determines which table to pull the date from:
Last(IIf([Grooms_Activity_Dates].[DueDate] Is Not
Null,[Grooms_Activity_Dates].[DueDate],[Grooms_Ckts].[DueDate])) AS DueD

Can you help fix my strWhere statement so it will only pull current year
records?? I've tried a couple different variations with Year(DueDate) and
Year(DueD), but nothing has worked so far.

I'll want to do the same for the previous year.

Private Sub Command106_Click()
On Error GoTo Err_Command106_Click

Dim stDocName As String
Dim strWhere As String
stDocName = "Cancelled"
strWhere = Year(Date)
DoCmd.OpenReport stDocName, acPreview

Exit_Command106_Click:
Exit Sub

Err_Command106_Click:
MsgBox Err.Description
Resume Exit_Command106_Click

End Sub

Thank you!
Mary
 
D

Douglas J. Steele

Private Sub Command106_Click()
On Error GoTo Err_Command106_Click

Dim stDocName As String
Dim strWhere As String
Dim strCondition As String

stDocName = "Cancelled"
strWhere = "Year(DueD) = Year(Date)"
DoCmd.OpenReport stDocName, acPreview, , strWhere

Exit_Command106_Click:
Exit Sub

Err_Command106_Click:
MsgBox Err.Description
Resume Exit_Command106_Click

End Sub
 
M

Mary

I get a prompt for "Date". When I click OK, there's no data. There are some
that should show up.

Any suggestions?
Thanks again,
Mary

Douglas J. Steele said:
Private Sub Command106_Click()
On Error GoTo Err_Command106_Click

Dim stDocName As String
Dim strWhere As String
Dim strCondition As String

stDocName = "Cancelled"
strWhere = "Year(DueD) = Year(Date)"
DoCmd.OpenReport stDocName, acPreview, , strWhere

Exit_Command106_Click:
Exit Sub

Err_Command106_Click:
MsgBox Err.Description
Resume Exit_Command106_Click

End Sub


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Mary said:
I'd like to add buttons for current year and previous year to a form. The
report is pulling all records. The field in the underlying query is
DueDate,
the field on the report is DueD.

There is an if statement that determines which table to pull the date
from:
Last(IIf([Grooms_Activity_Dates].[DueDate] Is Not
Null,[Grooms_Activity_Dates].[DueDate],[Grooms_Ckts].[DueDate])) AS DueD

Can you help fix my strWhere statement so it will only pull current year
records?? I've tried a couple different variations with Year(DueDate) and
Year(DueD), but nothing has worked so far.

I'll want to do the same for the previous year.

Private Sub Command106_Click()
On Error GoTo Err_Command106_Click

Dim stDocName As String
Dim strWhere As String
stDocName = "Cancelled"
strWhere = Year(Date)
DoCmd.OpenReport stDocName, acPreview

Exit_Command106_Click:
Exit Sub

Err_Command106_Click:
MsgBox Err.Description
Resume Exit_Command106_Click

End Sub

Thank you!
Mary
 
M

Mary

I got it, changed one line:

strWhere = "Year(DueD) = Year(Date())"

Thanks again,
Mary

Douglas J. Steele said:
Private Sub Command106_Click()
On Error GoTo Err_Command106_Click

Dim stDocName As String
Dim strWhere As String
Dim strCondition As String

stDocName = "Cancelled"
strWhere = "Year(DueD) = Year(Date)"
DoCmd.OpenReport stDocName, acPreview, , strWhere

Exit_Command106_Click:
Exit Sub

Err_Command106_Click:
MsgBox Err.Description
Resume Exit_Command106_Click

End Sub


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Mary said:
I'd like to add buttons for current year and previous year to a form. The
report is pulling all records. The field in the underlying query is
DueDate,
the field on the report is DueD.

There is an if statement that determines which table to pull the date
from:
Last(IIf([Grooms_Activity_Dates].[DueDate] Is Not
Null,[Grooms_Activity_Dates].[DueDate],[Grooms_Ckts].[DueDate])) AS DueD

Can you help fix my strWhere statement so it will only pull current year
records?? I've tried a couple different variations with Year(DueDate) and
Year(DueD), but nothing has worked so far.

I'll want to do the same for the previous year.

Private Sub Command106_Click()
On Error GoTo Err_Command106_Click

Dim stDocName As String
Dim strWhere As String
stDocName = "Cancelled"
strWhere = Year(Date)
DoCmd.OpenReport stDocName, acPreview

Exit_Command106_Click:
Exit Sub

Err_Command106_Click:
MsgBox Err.Description
Resume Exit_Command106_Click

End Sub

Thank you!
Mary
 

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