Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8256745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:57:47+00:00 2026-06-08T01:57:47+00:00

I’ve been looking a while now for a solution to export a query with

  • 0

I’ve been looking a while now for a solution to export a query with open parameters. I need to export a Query as a Formatted Excel Spreadsheet and can’t create additional Tables, Queries, Forms, or Reports to the Database being used. I use DoCmd.OutputTo as it exports a formatted query unlike DoCmd.TransferSpreadsheet however I can’t seem to export the query with defined parameters. I need to include the parameters or else the user will be forced to input the start and end date three times a piece as the database for some reason asks for the startDate and endDate twice and in order to keep the excel spreadsheet and the subsequent outlook section consistant i would have to ask the user to input their previous parameters again

Sub Main()
On Error GoTo Main_Err


'Visually Display Process
DoCmd.Hourglass True

Dim fpath As String
Dim tname As String
Dim cname As String
Dim tType As AcOutputObjectType
Dim tempB As Boolean

fpath = CurrentProject.path & "\"
'tType = acOutputTable
'tname = "APPROVED SWPS FOR LOOK AHEAD & BAR CHART"
tType = acOutputQuery
tname = "ASFLA&BC Query"
cname = "Temp BPC Calendar"


Dim qdfQry As DAO.QueryDef
Dim strStart As String
Dim strEnd As String

Set qdfQry = CurrentDb().QueryDefs(tname)


'strStart = InputBox("Please enter Start date (mm/dd/yyyy)")
'strEnd = InputBox("Please enter Start date (mm/dd/yyyy)")


qdfQry.Parameters("ENTER START DATE") = FormatDateTime("6/30/12", vbShortDate)   'strEnd
qdfQry.Parameters("ENTER END DATE") = FormatDateTime("7/1/12", vbShortDate) 'strStart





tempB = Backup(fpath, qdfQry, tType)
If (Not tempB) Then
    MsgBox "Excel Conversion Ended Prematurely..."
    Exit Sub
End If

'    tempB = sendToOutlook(qdfQry, cname)
'    If (Not tempB) Then
'        MsgBox "Access Conversion Ended Prematurely..."
 '        Exit Sub
'    End If

MsgBox "Procedure Completed Successfully"

Main_Exit:
    DoCmd.Hourglass False
    Exit Sub

 Main_Err:
    DoCmd.Beep
    MsgBox Error$
    Resume Main_Exit
End Sub


'************************************************************************************
'*
'*                                      Excel PORTION
'*
'************************************************************************************



Public Function Backup(path As String, db As DAO.QueryDef, Optional outputType As     AcOutputObjectType) As Boolean
On Error GoTo Error_Handler
    Backup = False
    Dim outputFileName As String
Dim name As String
Dim tempB As Boolean

'Set Up All Name Variablesand
name = Format(Date, "MM-dd-yy") & ".xls"

'Cleans Directory of Any older files and places them in an archive
SearchDirectory path, "??-??-??.xls", name

'See If File Can Now Be Exported. If Already Exists ask to overwrite
outputFileName = path & name

tempB = OverWriteRequest(outputFileName)



If tempB Then
    'Formats The Table And Exports Into A Formatted SpreadSheet
    'Checks if an output type was added to the parameter if not defualt to table
    If Not IsMissing(outputType) Then
        DoCmd.OutputTo outputType, db.name, acFormatXLS, outputFileName, False
    Else
        DoCmd.OutputTo acOutputTable, db.name, acFormatXLS, outputFileName, False
    End If
Else
    Exit Function
End If



Backup = True

Error_Handler_Exit:
    Exit Function

Error_Handler:
    MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf & "Error Number: " & _
Err.number & vbCrLf & "Error Source: Main Excel Backup" & vbCrLf & "Error Description: " & _
Err.Description, vbCritical, "An Error has Occured!"

Resume Error_Handler_Exit
End Function

The SQL currently given looks like similar to below with omitted fields for for clarity

PARAMETERS [ENTER START DATE] DateTime, [ENTER END DATE] DateTime;
SELECT [SWPS].STATION,
       [SWPS].START_DATE, 
       [SWPS].END_DATE, 
FROM [SWPS]
WHERE ((([SWPS].STATION) 
Like ("*")) 
AND (([SWPS].START_DATE)<=[ENTER END DATE]) 
AND (([SWPS].END_DATE)>=[ENTER START DATE]) 
AND (([SWPS].SWP_STATUS) In ("A","P","W","T","R")));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T01:57:49+00:00Added an answer on June 8, 2026 at 1:57 am

    I suggest you change the sql of the query.

    Dim qdfQry As DAO.QueryDef
    Dim strStart As String
    Dim strEnd As String
    
    ''You could use a query specifically for this
    Set qdfQry = CurrentDb.QueryDefs(tname)
    
    sSQL=qdfQry.SQL
    
    NewSQL = "SELECT [SWPS].STATION, [SWPS].START_DATE, [SWPS].END_DATE, " _
           & "FROM [SWPS] WHERE [SWPS].STATION Like '*' " _
           & "AND [SWPS].SWP_STATUS In ('A','P','W','T','R') " _
           & "AND [SWPS].START_DATE)<=#" & Format(DateStart, "yyyy/mm/dd") & "# " _
           & "AND [SWPS].END_DATE)>=#" & Format(DateEnd, "yyyy/mm/dd") & "#"
    
    qdfQry.SQL = NewSQL
    
    ''Do the excel stuff
    
    ''Reset the query
    qdfQry.SQL = sSQL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
Does anyone know how can I replace this 2 symbol below from the string
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.