How can i re-write the excel file when exporting an access table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • harry2012
    New Member
    • Jan 2012
    • 7

    How can i re-write the excel file when exporting an access table

    Hello,

    I do have an access form called T4, which is exported to an excel file, where i do have complex formulas and calculations.

    I would some assistance in exporting the table to excel. I cannot re-write the excel file every time the form is edited. When i execute the macro to export them to excel, it gives an error.


    Here is the code:

    Code:
    Option Compare Database
     
    Function MacroT4()
    
       Dim xlApp As Excel.Application
        Dim xlWB As Excel.Workbook
        Dim xlWS As Excel.Worksheet
       Dim acRng As Variant
        Dim xlRow As Integer
       
            Dim rst As Recordset
           Set xlApp = New Excel.Application
           Set xlWB = xlApp.Workbooks.Open("C:\Desktop\TAX\Slips.xls")
          Set xlWS = xlWB.Worksheets("T4A")
      
          xlRow = (xlWS.Columns("A").End(xlDown).Row)
     
          
          Set rst = Form.OpenRecordset
      
           Dim c As Integer
          c = 1
           xlRow = 3
    
           Do Until rst.EOF
               For Each acRng In rst.Fields
                   xlWS.Cells(xlRow, c).Formula = acRng
                   c = c + 1
             Next acRng
               xlRow = 3
               c = 1
             rst.MoveNext
               If xlRow > 10 Then GoTo rq_Exit
          Loop
     
    rq_Exit:
         rst.Close
          Set rst = Nothing
           Set xlWS = Nothing
          xlWB.Close acSaveYes
         Set xlWB = Nothing
          xlApp.Quit
         Set xlApp = Nothing
        Exit Function
        
    End Function

    Any help is appreciated. Thanks in advance.
    Attached Files
    Last edited by Niheel; Jan 24 '12, 08:02 PM.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Please use code tags when posting code.

    You didn't say what the error is.

    Comment

    • harry2012
      New Member
      • Jan 2012
      • 7

      #3
      There is no error, it exports it when the macro is run . But whenever i eidt the form it will not export or re-write the table on the excel file.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        You said, and I quote "When i execute the macro to export them to excel, it gives an error." If there is an error we need to know it.

        Editing the form shouldn't cause an export or rewrite the table in the excel file. I don't know why you think it would. The form design and the excel file are separate entities and not linked in any way.

        Comment

        Working...