URLDownloadToFile possibly caching (1 Viewer)

Laurad

Registered User.
Local time
Today, 16:39
Joined
Jan 16, 2011
Messages
68
I have a very small Access 2002 application which works on Windows 7, but the same coding on Access 2013 with Windows 8 does not work. I think the issue is that once an image is downloaded, it is being cached on the Access 2013/Windows 8 computer.

I monitor a wildlife cam which has refresh images every 15 seconds, no live streaming. Their website refreshes the image every 15 seconds, displays the refreshed image in a box on the website page, and the image always has the same name, eagle.jpg.

I wrote a little code that runs a timer - and every 15 seconds runs the code to download the image eagle.jpg into a folder with the name eagle20150110 1255.jpg - i.e., the exact date and time so that I can save many hours of images and review them all later as I cannot watch the cam all day.

This coding has worked perfectly on the 2003/Windows 7 system and still does, but on the 2013/Windows 8.1 the image does not refresh - in other words, the exact same image keeps getting downloaded every 15 seconds even though on the webiste it is refreshin. I think the computer "thinks" it was successful in downloading the requested image and therefore repeats it.

Other than the loop for the 15 second timing, my line of code is:

strWebsite is the URL for the website
strPath is the location on the computer where to save the files.

URLDownloadToFile 0, strWebsite, strPath, 0, 0

Once 10 hours have elapsed, the loop ends and I have 10 hours of images to preview. It works perfectly on one computer but not the other.

Thanks
Laura
 

MarkK

bit cruncher
Local time
Today, 08:39
Joined
Mar 17, 2004
Messages
8,193
URLDownloadToFile 0, strWebsite, strPath, 0, 0
What are the zeros? What is the code for URLDownloadToFile?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 16:39
Joined
Feb 19, 2013
Messages
16,711
it's an API

Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
"URLDownloadToFileA" ( _
ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long

Laura - Don't know if this will solve you problem but if you've moved from 2002 which is clearly 32bit and now on 2013 which could be 64bit (I presume there is a choice) then you need to change the above to

Private Declare PtrSafe FunctionURLDownloadToFile Lib "urlmon" Alias _
"URLDownloadToFileA" ( _
ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
 

Laurad

Registered User.
Local time
Today, 16:39
Joined
Jan 16, 2011
Messages
68
Thank you CJ_London. With my limited knowledge, could you explain how I would then use that Function, if that's ok. I do very basic programming in Access VBA and don't really understand what API means in this context.

MarkK I'm not sure what the 0's were, only that in my case I didn't need to put anything there. The code works on the Windows 7 computer.

Thanks and apologies for my limited knowledge.
Laura
 

CJ_London

Super Moderator
Staff member
Local time
Today, 16:39
Joined
Feb 19, 2013
Messages
16,711
I've never used it so don't think I can help

here is a link to the MS site which refers to it

http://msdn.microsoft.com/en-us/library/ie/ms775123(v=vs.85).aspx

It is for C++ but the explanation of what it does and the parameters will be the same.

However since it previously worked and the only change is to a later version of Access on a different operating system the issue must be to do with that.

I presume you have upgraded the db to 2013 (ie. running a accdb, not a mdb) and added ptrSafe as per my previous post
 

Laurad

Registered User.
Local time
Today, 16:39
Joined
Jan 16, 2011
Messages
68
I added PtrSafe to the declaration and converted the database too accdb, closed and opened it and still the images will not refresh. They do refresh if I close the database and reopen it, then an up to date image appears, but again, it just keeps repeating, it's still being cached.
Thanks for your patience.
Laura
 

CJ_London

Super Moderator
Staff member
Local time
Today, 16:39
Joined
Feb 19, 2013
Messages
16,711
I'm not sure what else to suggest - is the file actually being saved to disk?

Is the folder path the same

Have you tried debugging and following the code?

Does strpath include the filename? - your original post says it is the location where to save the files

Assuming it does, is it adding the same date/time to the file name or is this incrementing?
 

Laurad

Registered User.
Local time
Today, 16:39
Joined
Jan 16, 2011
Messages
68
Hi, yes, the image gets saved every 15 seconds with a new filename which is

eagles+YYYYMMDD HHMM

but it's the same image each time, not matter how much time passes. I can Close Access completely, restart it and the application and the next image to be saved will the the current image, but it keeps on saving the same image, as if the computer "thinks" it has downloaded the required image and does not seek the new one each time.

The website I'm saving from obviously overwrites their refresh picture each time, every 15 seconds, but uses the exact same name each time, "eagle.jpg". The code definitely works on the older computer and I have changed nothing now except what you suggested "PtrSafe". The only other bit of coding is the timer which loops every 15 seconds and each 15 seconds tries to retrieve the current eagle.jpg file.

Could it be something in the Registry?

Laura
 

Users who are viewing this thread

Top Bottom