none
visual basic in Access to output as an Excel application

คำตอบ

  • Here is code that will put a query called qlkpBusinessType into a spreadsheet.

    ------------------
    Private Sub MyTestForAnswer()
    On Error GoTo Err_Handler

        Dim strSQL As String
        
        strSQL = "qlkpBusinessType"
        DoCmd.RunCommand acCmdOutputToExcel

    Exit_Handler:
        Exit Sub
    Err_Handler:
        MsgBox Err.Number, Err.Description
        Resume Exit_Handler

    End Sub
    ----------------


    Jeanette Cunningham

    • ทำเครื่องหมายเป็นคำตอบโดย Bruce Song 10 เมษายน 2555 8:43
    30 มีนาคม 2555 5:39
  • Well what are you trying to export to Excel? A query/ Table I presume?

    In case of of a Query/ Table you can use the DoCmd.TransferSpreadsheet for that, see below link:

    http://msdn.microsoft.com/en-us/library/bb214134%28v=office.12%29.aspx

    In case you want to use the DoCmd.RunCommand, you can do something like this:

    Private Sub cmdYourCommandButton_Click()
        ' open a query
        DoCmd.OpenQuery "qryYourQueryName"
         ' export the Query
           DoCmd.RunCommand acCmdOutputToExcel
         ' close the query
        DoCmd.Close acQuery, "qryYourQueryName"
    
    End Sub

    But you haven't control over where (the file location) the Query will be saved for example (It will be saved in Default file location).

    Hope this helps,


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"

    Please vote an answer helpful if they helped. Please mark an answer(s) as an answer when your question is being answered.


    • แก้ไขโดย danishani 30 มีนาคม 2555 5:50 typo
    • ทำเครื่องหมายเป็นคำตอบโดย Bruce Song 10 เมษายน 2555 8:43
    30 มีนาคม 2555 5:49

ตอบทั้งหมด

  • Please post Access questions to the Access for Developers forum. This forum is primarily for Visual Basic .NET.

    Paul ~~~~ Microsoft MVP (Visual Basic)

    29 มีนาคม 2555 12:40
  • Here is code that will put a query called qlkpBusinessType into a spreadsheet.

    ------------------
    Private Sub MyTestForAnswer()
    On Error GoTo Err_Handler

        Dim strSQL As String
        
        strSQL = "qlkpBusinessType"
        DoCmd.RunCommand acCmdOutputToExcel

    Exit_Handler:
        Exit Sub
    Err_Handler:
        MsgBox Err.Number, Err.Description
        Resume Exit_Handler

    End Sub
    ----------------


    Jeanette Cunningham

    • ทำเครื่องหมายเป็นคำตอบโดย Bruce Song 10 เมษายน 2555 8:43
    30 มีนาคม 2555 5:39
  • Well what are you trying to export to Excel? A query/ Table I presume?

    In case of of a Query/ Table you can use the DoCmd.TransferSpreadsheet for that, see below link:

    http://msdn.microsoft.com/en-us/library/bb214134%28v=office.12%29.aspx

    In case you want to use the DoCmd.RunCommand, you can do something like this:

    Private Sub cmdYourCommandButton_Click()
        ' open a query
        DoCmd.OpenQuery "qryYourQueryName"
         ' export the Query
           DoCmd.RunCommand acCmdOutputToExcel
         ' close the query
        DoCmd.Close acQuery, "qryYourQueryName"
    
    End Sub

    But you haven't control over where (the file location) the Query will be saved for example (It will be saved in Default file location).

    Hope this helps,


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"

    Please vote an answer helpful if they helped. Please mark an answer(s) as an answer when your question is being answered.


    • แก้ไขโดย danishani 30 มีนาคม 2555 5:50 typo
    • ทำเครื่องหมายเป็นคำตอบโดย Bruce Song 10 เมษายน 2555 8:43
    30 มีนาคม 2555 5:49