Share via

Export data to Excel using date range

Anonymous
2010-07-24T17:01:20+00:00

Hi I use the following code to open a report, by entering the dates in the txtStartDate field and the txtEndDate field.

 Dim stDocName As String

     Dim strWhere As String

    strWhere = "[Date] between #" & Format(Me.txtStartDate, "dd-mmm-yy") & "# AND #" & Format(Me.txtEndDate, "dd-mmm-yy") & "#"

    stDocName = "rptSouthW"

    DoCmd.OpenReport stDocName, acPreview, , strWhere

    DoCmd.RunCommand acCmdZoom100

How do I get the following code below to work in the same way as the code above so that I only have to end the dates once, the reason I ask is I have several reports to export to Excel and its a pain to keep entering the date range.

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qryClaimsDetail", "P:\Incident Report.xls", , "Claim Detail"

Thanks

Bob

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2010-07-26T07:34:41+00:00

Marshall

The following code works fine.

Between Forms!frmReportPrinter.txtStartDate AND Forms!frmReportPrinter.txtEndDate

Thank you everyone for your help.

Regards,

Bob

Was this answer helpful?

0 comments No comments

6 additional answers

Sort by: Most helpful
  1. Anonymous
    2010-07-26T16:45:29+00:00

    Hi Marshall,

    You are right - my mistake.

    Nadia

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2010-07-26T03:06:26+00:00

    That would make everything a text string and then Between would not make sense.

    Was this answer helpful?

    0 comments No comments