+ Reply to Thread
Results 1 to 9 of 9

Data connection refresh on Certain Days

  1. #1
    Registered User
    Join Date
    10-12-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    62

    Data connection refresh on Certain Days

    I have a data connections from three databases (2 in Access and one from JD Edwards). This data is constantly and manually refreshed throughout the day as information from JD Edwards is updated.

    Is there a way to limit a user to only refresh the data on certain days of the week? Example only on Tuesday's, Wednesday's and Thursday's

    Due to the the Financials and order confirmations work, data is combined then separated on Friday-Monday and causes #Ref's on the Spreadsheet if refreshed on any of those days.

  2. #2
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Data connection refresh on Certain Days

    Yeah you can include an If Statement in the code, if <> a day you want then Exit Sub.
    Please ensure you mark your thread as Solved once it is. Click here to see how.
    If a post helps, please don't forget to add to our reputation by clicking the star icon in the bottom left-hand corner of a post.

  3. #3
    Registered User
    Join Date
    09-16-2014
    Location
    United States
    MS-Off Ver
    Office 2013
    Posts
    11

    Re: Data connection refresh on Certain Days

    Yeah you can include an If Statement in the code, if <> a day you want then Exit Sub.
    That'll work for the normal refresh options?

  4. #4
    Registered User
    Join Date
    10-12-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    62

    Re: Data connection refresh on Certain Days

    Not sure I understand. Would I build the whole data connection event in VBA and not use the Data connection built in?

  5. #5
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Data connection refresh on Certain Days

    Can you not do that with an event handler? if trying to refresh and WED then say they cant and exit?

  6. #6
    Registered User
    Join Date
    09-16-2014
    Location
    United States
    MS-Off Ver
    Office 2013
    Posts
    11

    Re: Data connection refresh on Certain Days

    Unfortunately, that's not something I would have know was possible. Anyway, I tested this article and it worked well. I don't know if it will automatically initialize when the workbook is opened, and if not, then it needs initialized int he WorkbookOpen event, I think, Anyway, it seemed to work by making a messagebox pop up when the data would be refreshed, meaning you could force-cancel it if it's the wrong day.

  7. #7
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Data connection refresh on Certain Days

    Workbook open event IS a form of event handling. Unfortunately I am on my phone and cannot play with the ideas I have at the moment.

    Take a look at this.
    http://stackoverflow.com/questions/2...-data-in-excel

  8. #8
    Registered User
    Join Date
    09-16-2014
    Location
    United States
    MS-Off Ver
    Office 2013
    Posts
    11

    Re: Data connection refresh on Certain Days

    Quote Originally Posted by mikeTRON View Post
    Workbook open event IS a form of event handling. Unfortunately I am on my phone and cannot play with the ideas I have at the moment.

    Take a look at this.
    http://stackoverflow.com/questions/2...-data-in-excel
    Yes, I just meant that the refresh event seems to require initialization, and that initialization is setup as a macro you manually run (on that page). I was simply saying that initialization should be moved to the Workbook Open event to automate it so it affects everyone all the time without having to remember anything.

    Just to make sure I was right, I checked, and yes, that bit of code at the end that can just be plugged directly into the Workbook Open event and it works fine (and I checked without it, and it doesn't work, then).

    So, here you go. Follow the direction the page I linked to tells you to, (you don't need to create the data connection), but use this code for the Class Module (first section):
    Please Login or Register  to view this content.
    When it tells you to create the Module, ignore that. Instead, double-click ThisWorkbook on the left pane (Project Explorer) for the workbook you're in, and paste this (replacing the empty sub that's already there):
    Please Login or Register  to view this content.
    This may need to be tweaked if you have multiple tables or if they're on sheets other than the first one. Mike will have to help with that, though, because that's a bit beyond my skill set. Well, to change it to another sheet, just change "Sheets(1)" to the number of your sheet, but I imagine you'll want it to work for all sheets, and that requires iterating through them. I can do that, but I don't know how to incorporate the results with the first section of code.

    Result: if you try to refresh on Tuesday, Wednesday, or Thursday, it refreshes like normal. If you try to refresh on other days, a message box informs you "You can't refresh today." and nothing happens.
    Last edited by Xander9009; 09-17-2014 at 03:40 PM.

  9. #9
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Data connection refresh on Certain Days

    Quote Originally Posted by Xander9009 View Post
    Yes, I just meant that the refresh event seems to require initialization, and that initialization is setup as a macro you manually run (on that page). I was simply saying that initialization should be moved to the Workbook Open event to automate it so it affects everyone all the time without having to remember anything.

    Just to make sure I was right, I checked, and yes, that bit of code at the end that can just be plugged directly into the Workbook Open event and it works fine (and I checked without it, and it doesn't work, then).

    So, here you go. Follow the direction the page I linked to tells you to, (you don't need to create the data connection), but use this code for the Class Module (first section):
    Please Login or Register  to view this content.
    When it tells you to create the Module, ignore that. Instead, double-click ThisWorkbook on the left pane (Project Explorer) for the workbook you're in, and paste this (replacing the empty sub that's already there):
    Please Login or Register  to view this content.
    This may need to be tweaked if you have multiple tables or if they're on sheets other than the first one. Mike will have to help with that, though, because that's a bit beyond my skill set. Well, to change it to another sheet, just change "Sheets(1)" to the number of your sheet, but I imagine you'll want it to work for all sheets, and that requires iterating through them. I can do that, but I don't know how to incorporate the results with the first section of code.

    Result: if you try to refresh on Tuesday, Wednesday, or Thursday, it refreshes like normal. If you try to refresh on other days, a message box informs you "You can't refresh today." and nothing happens.

    Nice! That should be enough to lock them out.

    My biggest concern with workbook events is there always seems to be some little thing that causes it to break or some random bug that then I am responsible for handling instead of just telling the people, DO NOT DO THIS. So I have been trying to stay away from it lately LoL.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 07-09-2014, 01:38 PM
  2. Formatting not updating upon data connection refresh
    By jmewebb in forum Excel General
    Replies: 1
    Last Post: 06-03-2014, 02:05 PM
  3. VBA Data Connection Refresh when File is in use
    By Pierce Quality in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-09-2014, 01:42 PM
  4. Refresh Data Connection Compatibility 2007 vs 2003
    By cfherd in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-02-2012, 05:13 AM
  5. Refresh SQL data link by macro instead of excels connection wizard
    By mcinnes01 in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 11-23-2010, 11:11 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1