Results 1 to 6 of 6
  1. #1
    drunkenneo is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2013
    Posts
    199

    Error of query exporting

    Hi My code is:

    Private Sub btPending_Click()
    Dim penddate As Date
    Dim a, str As String
    Dim qdfTemp As DAO.QueryDef
    Dim strQDF As String
    If (CStr(Format(Now(), "dddd")) <> "Tuesday" Or CStr(Format(Now(), "dddd")) <> "Thursday") Then
    If MsgBox("Today is not Tuesday/Thursday" & vbLf & "Do you Still want to continue", vbYesNo) = vbNo Then
    Exit Sub
    End If
    End If

    penddate = PlusWorkdays(Format("11/12/2013", "dd/mm/yyyy"), -10)
    'To Do

    str = " ...... " & _
    "WHERE (((orderInvoice.dateRecieved)<#" & penddate & " # ) AND ((partnerBiWeekly.Description)=" & Chr(34) & "Daily" & Chr(34) & ") AND ((orderList.deliveredDate)<> " & Chr(34) & "Cancelled" & Chr(34) & ") AND ((orderList.deliveredDate) Is Null))"

    Debug.Print str

    Set qdfTemp = CurrentDb.CreateQueryDef(strQDF, str)
    qdfTemp.Close


    Set qdfTemp = Nothing

    a = Format(Now(), "dd.mm.yyyy")

    'DoCmd.TransferSpreadsheet , acExport, acTypespreadsheetTypeExcel9, strQDF, "C:\PendingOrders_" & a & ".xls", False

    'DoCmd.OutputTo acQuery, "str", "cFormatXLS", _
    "C:\PendingOrders_" & Format(Now(), "dd.mm.yyyy") & ".xls", True

    DoCmd.OutputTo acOutputQuery, strQDF, acFormatXLS, "C:\PendingOrders_" & a & ".xls", False

    CurrentDb.QueryDefs.Delete strQDF

    Its big...But bottom line isit shows error 2487, the Object Type argument for action or method is blank or invalid.

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    put code markers around your code to get it to be more readable like this (use the word CODE in square brackets to start your code /CODE in square brackets to end your code):

    Code:
    Private Sub btPending_Click()
    Dim penddate As Date
    Dim a, str As String
        Dim qdfTemp As DAO.QueryDef
        Dim strQDF As String
    
    If (CStr(Format(Now(), "dddd")) <> "Tuesday" Or CStr(Format(Now(), "dddd")) <> "Thursday") Then
         If MsgBox("Today is not Tuesday/Thursday" & vbLf & "Do you Still want to continue", vbYesNo) = vbNo Then
             Exit Sub
         End If
    End If
    
    penddate = PlusWorkdays(Format("11/12/2013", "dd/mm/yyyy"), -10)
    'To Do
    
    str = " ...... " & _
    "WHERE (((orderInvoice.dateRecieved)<#" & penddate & " # )  AND ((partnerBiWeekly.Description)=" & Chr(34) & "Daily" &  Chr(34) & ") AND ((orderList.deliveredDate)<> " & Chr(34)  & "Cancelled" & Chr(34) & ") AND ((orderList.deliveredDate)  Is Null))"
    
    Debug.Print str
    
    Set qdfTemp = CurrentDb.CreateQueryDef(strQDF, str)
     qdfTemp.Close
            Set qdfTemp = Nothing
    
    a = Format(Now(), "dd.mm.yyyy")
    
    'DoCmd.TransferSpreadsheet , acExport, acTypespreadsheetTypeExcel9, strQDF, "C:\PendingOrders_" & a & ".xls", False
    'DoCmd.OutputTo acQuery, "str", "cFormatXLS", "C:\PendingOrders_" & Format(Now(), "dd.mm.yyyy") & ".xls", True
          DoCmd.OutputTo acOutputQuery, strQDF, acFormatXLS, "C:\PendingOrders_" & a & ".xls", False
     
      CurrentDb.QueryDefs.Delete strQDF
    I assume based on your post that this is erroring out on this line:

    DoCmd.OutputTo acOutputQuery, strQDF, acFormatXLS, "C:\PendingOrders_" & a & ".xls", False


    Where are you setting strQDF? looks like you're building a SQL string under the STR variable but I dont' see where strqdf is being defined.

    If it's in a different part of your code and you debug.print str and actually paste that SQL code into a query window do you get results you expect or does the query itself bomb out?

    EDIT:

    Is there a reason you're trying to save this as a static query every time you run it? you can export to an excel file based on a valid SQL statement without saving it in your database in most instances.

  3. #3
    drunkenneo is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2013
    Posts
    199
    Here date is calulated on basis of working days and query is made for that, is there any other way to do it

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    I do not understand your response

  5. #5
    drunkenneo is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2013
    Posts
    199
    From the table there is column daterecieved, and i have to see if the date recieved is above 10 working days then i need names of theclientsin an excel sheet.

    Here i have calcolated back 10 working days from function plusworkingdaysfrom now, here after calculating the date i search the date is more than pendate on that basis i eprt the sheet

  6. #6
    drunkenneo is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2013
    Posts
    199
    I have solved the error and now the code is working superb, thanks for lot of combinations

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 06-27-2013, 12:38 PM
  2. Query contents are deleted after exporting the query results
    By alfcee in forum Import/Export Data
    Replies: 6
    Last Post: 11-13-2012, 09:35 AM
  3. Error while exporting the data
    By riaarora in forum Access
    Replies: 1
    Last Post: 08-12-2012, 12:57 PM
  4. Error while exporting the data
    By riaarora in forum Access
    Replies: 2
    Last Post: 08-11-2012, 11:21 AM
  5. Error Message after exporting MS Access Table
    By samjoseph in forum Access
    Replies: 1
    Last Post: 02-22-2010, 04:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums