Results 1 to 11 of 11
  1. #1
    jo15765's Avatar
    jo15765 is offline Expert
    Windows XP Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672

    Converting Excel VBA to Access VBA


    How would I change this code over from Excel to Access code:
    Code:
    Dim wks As Worksheet
    Dim qt As QueryTable
     
    For Each wks In Worksheets
    For Each qt In wks.QueryTables
    qt.Refresh BackgroundQuery:=False
    Next qt
    Next wks
     
    Set qt = Nothing
    Set wks = Nothing
    The reason I am needing to, is I imported excel modules into access, and it doesn't appear to run this module.

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    I don't use excel if I can help it. What is this code doing for you in excel?

  3. #3
    jo15765's Avatar
    jo15765 is offline Expert
    Windows XP Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    Taking all of the queries on in an excel spreadsheet and running them basically. It is what I called an "Auto-refresh" query, since the macro was doing it instead of me manually having to do it

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    YOu don't need to refresh queries in Access. Any query you run against your data automatically uses the most recent information, if you want to modify the results you just alter the criteria.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    You imported modules but not the data? You still want to update the Excel worksheets?
    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.

  6. #6
    jo15765's Avatar
    jo15765 is offline Expert
    Windows XP Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    June it sounds like you are on the same page as me. Yes, I still need the data in excel to refresh, hence running that VBA.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    That prompts two-part question - why import modules and run from Access or why not import data and make it all Access app?

    How did you execute the code when it was in Excel?
    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.

  8. #8
    jo15765's Avatar
    jo15765 is offline Expert
    Windows XP Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    The data is in excel, and it is a report with about 4 queries in it. I had a Workbook_Open() event that would run that code so the queries would auto-refresh.

    The boss asked me to convert it from Excel to an access form, with buttons to press that would refresh the reports, hence me trying to convert the code from Excel to Access.

    Basically, I am needing to be able to push a button on a form, and once that button is pressed open up the specified Excel Report, then run that line of code to refresh the queries.

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    If you are not going to convert the data to Access and still want the workbook as the report output, I suggest you leave the code in Excel. Just use button in Access to open the Excel workbook.
    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.

  10. #10
    jo15765's Avatar
    jo15765 is offline Expert
    Windows XP Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    So actually leave that line of code in Excel, and have the button in access open the Excel Workbook?

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Exactly. Leave the Excel workbook set up as it was. Just open programmatically.
    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. Converting Excel IF to Access iiF???
    By robertr in forum Queries
    Replies: 5
    Last Post: 10-14-2011, 05:53 AM
  2. Converting to access from Excel
    By Alexpi in forum Database Design
    Replies: 3
    Last Post: 05-24-2011, 02:46 PM
  3. Converting Excel Macro into Access Module
    By diddyville in forum Modules
    Replies: 1
    Last Post: 03-28-2011, 07:02 PM
  4. Replies: 1
    Last Post: 02-21-2011, 09:55 PM
  5. Converting or using Access as a front end for Excel
    By jacko311 in forum Database Design
    Replies: 4
    Last Post: 11-07-2009, 12:19 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