PDA

View Full Version : Code execution has been interrupted



mdmackillop
10-09-2006, 07:24 AM
The code below is extracted from my Userform. With both of the If paths, I receive the "code interupted" message. The Userform opems correctly with the picture displayed if I click continue. There are no event items other than connected to buttons. Any thoughts as to what might cause this behaviour?

If Left(Fld, 1) = "Z" Then
With Application.FileSearch
.FileName = TextBox1.Text & ".jpg"
.LookIn = "C:\Scores Hotel Revised\"
.SearchSubFolders = True
.Execute
MyPic = .FoundFiles(1)
End With
Else
MyPic = "C:\Scores Hotel Revised\" & DirName(Fld) & "\" & _
Format(Num, String(Digits, "0")) & ".jpg"
End If
Me.Image1.Picture = LoadPicture(MyPic)

mvidas
10-09-2006, 08:15 AM
Hey Malcolm,

Since I'm sure the Debug button isn't enabled when you get this error, have you tried using debug statements to figure out which line causes the problem?If Left(FLD, 1) = "Z" Then
Debug.Print 1
With Application.FileSearch
Debug.Print 2
.FileName = TextBox1.Text & ".jpg"
Debug.Print 3
.LookIn = "C:\Scores Hotel Revised\"
Debug.Print 4
.SearchSubFolders = True
Debug.Print 5
.Execute
Debug.Print 6
MyPic = .FoundFiles(1)
Debug.Print 7
End With
Debug.Print 8
Else
Debug.Print 9
MyPic = "C:\Scores Hotel Revised\" & DirName(FLD) & "\" & _
Format(Num, String(Digits, "0")) & ".jpg"
Debug.Print 10
End If
Debug.Print 11
Me.Image1.Picture = LoadPicture(MyPic)
Debug.Print 12Just an idea, might help to determine whats holding it up

mdmackillop
10-09-2006, 08:43 AM
Hi Matt,
I've just been running an old programme for viewing photos in Excel, and 50% of the time I'm getting the same message. This is a different PC I'm using now. I'll need to try my code on my old one to see if it works there.

Jacob Hilderbrand
10-09-2006, 09:18 AM
You could try disabling the Cancen Key just to see:


Application.EnableCancelKey=xlDisabled


Then I would step through it line by line and see which line causes the problem (if there is a problem when you step through).

mdmackillop
10-09-2006, 09:44 AM
Stepping through works fine. When I go into debug in a non-Z item, the code is halted usually on the End Sub line, after the picure is loaded. Z items are a bit more random, but will continue to step through without error.

I've tested on my old PC (1.7Mhz) and everything runs perfectly. On this PC (2.8Mhz) it's tripping up.:dunno

Jacob Hilderbrand
10-09-2006, 11:53 AM
Can you post the workbook for us to test?

mdmackillop
10-09-2006, 12:25 PM
Hi Jake
Workbook as requested. Click the button and browse to a folder containing some JPG files

mdmackillop
10-09-2006, 12:29 PM
Hi Jake,
Just noticed that this works OK with files on the C drive, but interrupt occurs with files on the server.

Jacob Hilderbrand
10-09-2006, 02:40 PM
Works fine for me. So do you have some files on a shared drive? You could be timing out or something. Maybe try copying the file from the server to a local folder, then loading it into Excel.