Results 1 to 3 of 3
  1. #1
    riaarora is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2012
    Posts
    25

    Error while exporting the data

    Hi All,



    I have fronend and backend database. I have all data stored in another database (backend) and that database is password protected. I need to export some selected data into Excel which is created in the same process. Below is the code:

    Code:
    Private Sub ExportLeaversList(strWorkbook As String)
        On Error GoTo ERR_HANDLER
        
        Dim objApp As Object
        Dim strExcelFileName As String
        Dim varStatus As String
        Dim strTempQueryName As String
        Dim strSelectSQL As String
        Dim strPnPDatabaseName As String
        Dim strPnPDatabasePassword As String
        
        strTempQueryName = "BankersLeavers"
        
        DoCmd.SetWarnings False
        strSelectSQL = "SELECT * FROM tbl_Bankers WHERE [Exclude] = True"
        Set objApp = New Access.Application
        strPnPDatabaseName = ExtractDatabaseDetails.GetDatabasePath(gsPnPDatabaseID) & "\" & ExtractDatabaseDetails.GetDatabaseName(gsPnPDatabaseID)
        strPnPDatabasePassword = GetDatabasePassword(gsPnPDatabaseID)
        objApp.OpenCurrentDatabase strPnPDatabaseName, , strPnPDatabasePassword
        With objApp
            If .DCount("[Name]", "MSysObjects", "Left([Name],1) <> '~' AND [Type] = 5 AND [Name] = '" & strTempQueryName & "' ") <> 0 Then
                .DoCmd.DeleteObject acQuery, strTempQueryName
                .CurrentDb.QueryDefs.Refresh
            End If
            
            'Extract Secucash Detail Data
            .CurrentDb.CreateQueryDef strTempQueryName, strSelectSQL
            .CurrentDb.QueryDefs.Refresh
            .DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, strTempQueryName, strWorkbook, True '--> Error
            
            .DoCmd.DeleteObject acQuery, strTempQueryName
            .CloseCurrentDatabase
        End With
        Set objApp = Nothing
        
        DoCmd.SetWarnings True
        
    Exit_Err_Handler:
        Exit Sub
    ERR_HANDLER:
        MsgBox Err.Description
        DoCmd.Hourglass (False)
        varStatus = SysCmd(acSysCmdClearStatus)
        DoCmd.Hourglass (False)
        Resume Exit_Err_Handler
    End Sub
    Value of strWorkbook is C:\MyDoc\Taiwan_Week 23_20120809_2356.xlsx

    I'm getting error at below line
    .DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, strTempQueryName, strWorkbook, True

    Run-time error '3275':
    Unexpected error from external database driver (1309).

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,618
    Did you confirm that the query is actually changed and has the data? Not sure why you have to rebuild the query.

    Might be easier to populate a temp table in the frontend and use that table as source for the export.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    riaarora is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2012
    Posts
    25
    Thanks

    I have managed to solve the issue using below code

    Code:
    .DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, strTempQueryName, sWorkbookPath, True, sWorksheetName

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

Similar Threads

  1. Exporting Data to Excel from a Web database
    By need_help12 in forum Import/Export Data
    Replies: 1
    Last Post: 05-16-2012, 04:59 PM
  2. Exporting data to powerpoint
    By sharmaprashant22 in forum Import/Export Data
    Replies: 0
    Last Post: 05-03-2011, 12:28 AM
  3. Exporting only specific data
    By cypress in forum Access
    Replies: 1
    Last Post: 09-24-2010, 10:41 AM
  4. Error Message after exporting MS Access Table
    By samjoseph in forum Access
    Replies: 1
    Last Post: 02-22-2010, 04:08 PM
  5. Help with exporting data
    By wee in forum Import/Export Data
    Replies: 10
    Last Post: 09-24-2009, 01:15 AM

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