My Loop Keeps Running but the image doesn't update

Icarus38376

New Member
Joined
Jun 14, 2019
Messages
6
Hello Folks, I'm new at this so any help appreciated.
I have a form that starts on Workbook_Open. It simply displays an image that gets updated form another system. When the user select the Option_Button1, the code should get the picture, wait 5 seconds and then redisplay it. It does work most of the time, However many time it just stops without error. Also, the label1.caption shows me that the loop is still running, but the picture is not updated. The image has the date and time it was generated, that is how we know it has not been updated. IF yo go directly to the image, the time may be much later than shows on the form. Could it be that the image is getting cached? Any help appreciated.

Code:
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]'This Opens the Form
Private Sub Workbook_Open()
 bigStatusForm.Show vbModal
End Sub[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]'This start the loop to update the picture
Private Sub OptionButton1_Click()
Do While OptionButton1.Value = True
 i = i + 1
 WasteTime (5)
 Call doCopo
 bigStatusForm.Label1.Caption = i
Loop
End Sub[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
Sub doCopo()
On Error Resume Next
myPicture = "\\Desktop-iuf6vi7\Applications\Jobs\Reports\COPO_Status.jpg"[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]If Application.Workbooks.Count > 1 Then
 WasteTime (5)
Else
    IsFile = ((GetAttr(myPicture) And vbDirectory) <> vbDirectory)
    If IsFile = True Then
     Call getPicture(myPicture)
    End If
End If
End Sub[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
Sub getPicture(myPicture)
 bigStatusForm.Image1.Picture = LoadPicture(myPicture)
End Sub[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
Sub WasteTime(Seconds As Long)
 Dim EndTime As Double
 EndTime = Time() + Seconds / 24 / 60 / 60
 Do
      DoEvents
 Loop Until Time() >= EndTime
End Sub[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif][/FONT]
 
New Information*** I have slowed down the code so Workbook2 creates the .jpg image every 5 minutes and Worbook1 queries for the new image every 1 minute. This did not seem to fix the problem. But here is what is weird. While the macros are running (and I know they are running because my loop counter is incrementing) If I press the Microsoft Windows button on the keyboard the form updates correctly immediately. BTW the Form I am using to present the image takes up the whole screen. Any ideas? Does Modality have anything to do with this? Could the image be cached?
Any ideas welcome...
 
Upvote 0

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Forum statistics

Threads
1,214,614
Messages
6,120,517
Members
448,968
Latest member
Ajax40

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top