Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exit from a Function

Status
Not open for further replies.

balajee

Programmer
Joined
Jun 29, 2000
Messages
134
Location
NZ
Hi

I have a form. I call a procedure from my class module after clicking on a buttom. This procedure reads a text file line by line. It calls another function which checks if the present line read has a file path or not. If it does not find a file path I would like to convey the user that there is an error and the control should go to the form by discontinuing the procedure. I tried using "on error goto..." in the function and used the "show method of the form. But the procedure still contiues further.

Please help.

Thanks
 
The problem with you using on error goto is that this will only work if there is a system error. Try declaring a string variable which you populate if there is an error i.e. if it does not find a file path. Then just check this string to see if there's an error in it and if there is then display the error in a message box anduse the Exit Sub or Exit function command. Mark

The key to immortality is to make a big impression in this life!!
 
The function routine does not accept "Exit sub" and "Exit Function" I suppose will take me back to the procedure from where it was called which I do not want. I want the control to back to the calling form. I could set a flag in function and when there is error it is set to true and exit function, control being passed to the procedure where I check for this flag and use "Exit Sub". But then I will have to check this each time I read the line, Which I do not want because there are lots of lines for filepath in this text file.
 
I would suggest using err.raise and raise the error back up.

Handle business rules the same as system errors.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top