-
For whatever reason the program I am designing does not want to let me exit the sub, every time I try it gives me an error that says "Runtime Error 5: Invalid procedure or call argument". I have tried using an error trapping routine and it doesnt catch the error, I tried creating a line name and saying "if ... then goto skipsub" and I tried just saying "if ... then exit sub" but nothing works, by the way, here is the line of code that I can't exit the sub with, Does anyone have any idea what is causing this error??? I would really appriciate some suggestions, thanks!
If UCase(Trim(Mid(d$, 23, 25))) <> userlevel$ Then Close: Exit Sub
-
1. Do you have an file open?
2. IS d$ longer than 23?
-
Yes
A file is open, and d$ is not longer than 25, but I have similar if ... then statements in the program, and I have no problem with those, if you think it would help, I will e-mail you the whole sub, thanks for your help.
-
Try removing the colon and poutting them on seperate lines.
Also, instead of Close you could also try Close #1 (or whatever file you have open.
Can you post up your whole code?
-
Nope
Unfortunately, neither of those work, in fact I have similar lines of code in other parts of the program that work perfectly, I am really stumped, how else can you exit a sub, that is always when the crash occurs, just as the program exits the sub?
-
You can't use Exit Sub in a function or Property, go check that also. If it's not that, either post the whole sub here or send it to me
-
The code did run, i've just tested it, i removed the on error, caused me much erros but that one exiting the sub worked. What version are you using?
-
I would say that you are trying to exit sub before file is closed. I mean that file is closed by OS asynchronicaly and then OS returns message about completing file operation, but there is no Sub running any more. And this is what triggered Error 5, I beleive.
You should try Empty loop with DoEvents for a second or so, or check if file is closed as a loop condition. only after this you can exit sub.
-
-
That's not the case LG, i've tested his code. I suppose i need the whole project and the files attached to it to know where the problem is