Results 1 to 2 of 2
  1. #1
    buckwheat is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2013
    Posts
    144

    VBA to pull various processes together

    I have an imported excel spreadsheet in my Access database that needs to be updated each week with a fresh import. I also have an Update query that looks at the email field in the imported table and codes it to identify records without an email address. I then have a macro that exports the results to another specific excel spreadsheet.



    Is there VBA that will run step 1 & 2 below at the same time:

    IMPORT. . . REPORT . . . UPDATE
    1) Replace existing records in the current imported table (Survey - DB) when importing the new weekly update?
    2) Runs the Update query:

    UPDATE [Survey - DB Link] SET Email = Null
    WHERE instr([Email],"@")=0;

    EXPORT
    3) Instead of using a macro to export to a specific spreadsheet, VBA to export records and "add" a new tab to a specific spreadsheet. If I could have the option to name that tab before the export process, that would be great.

    Many thanks

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Yes, a single button Click event could execute all code.

    Why even need Excel component? What is method of import - can't just link to the Excel?

    VBA can certainly do whatever the macro does, and more.

    Here is one users solution for the export http://social.msdn.microsoft.com/For...3-a891fe1ae43b.

    Alternative to TransferSpreadsheet would be opening the existing workbook as an Excel object in VBA that could be manipulated. I modified code from the following and it almost totally works. Unfortunately an instance of Excel persists in Task Manager processes. Something about the Add worksheet line that is not right.
    http://social.msdn.microsoft.com/For...8-5617865b1e82
    http://www.mrexcel.com/archive/VBA/1869.html
    http://www.exceltip.com/st/Close_a_w...Excel/469.html

    Solution to the Add sheet code found at http://www.vbforums.com/showthread.p...xisting-sheets
    Can't get new sheet to add to end of sheets.

    Will need VBA reference to Microsoft Excel 12.0 Object Library.
    Code:
    Private Sub SaveRecordsetToExcelRange()
      '  Excel Objects:
      Dim objXL As Excel.Application
      Dim objWBK As Excel.Workbook
      Dim objRS As DAO.Recordset
      '  Open a DAO recordset on the query:
      Set objRS = CurrentDb.OpenRecordset("SELECT * FROM table1;")
      '  Open Excel and point to the cell where the recordset is to be inserted:
      Set objXL = New Excel.Application
      objXL.Visible = True
      Set objWBK = objXL.Workbooks.Open("C:\Temp\Test.xlsx")
      objWBK.Worksheets.Add().Name = "Test"
      objWBK.Worksheets("Test").Range("A1").CopyFromRecordset objRS
      objWBK.Close True
      objXL.Quit
      '  Destroy objects:
      Set objWBK = Nothing
      Set objXL = Nothing
      If Not objRS Is Nothing Then
        objRS.Close
        Set objRS = Nothing
      End If
    End Sub
    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.

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

Similar Threads

  1. How can pull this data?
    By cap.zadi in forum Queries
    Replies: 21
    Last Post: 01-23-2012, 03:09 AM
  2. Cannot pull value of 0
    By LilMissAttack in forum Queries
    Replies: 7
    Last Post: 08-01-2011, 11:08 AM
  3. How to pull lowest value?
    By TommyRex in forum Access
    Replies: 5
    Last Post: 10-25-2010, 02:09 PM
  4. Run 2 Processes in Separate Threads
    By matt_tapia in forum Programming
    Replies: 1
    Last Post: 08-06-2009, 12:33 PM
  5. Replies: 1
    Last Post: 08-22-2006, 04:27 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