proper code placement

D

DawnTreader

Hello All

i have this:

Private Sub Form_Current()
On Error GoTo Err_Form_Current

Call Visibility

Exit_Form_Current:
Exit Sub

Err_Form_Current:
If err = 2448 Then
Else
MsgBox "Error #: " & err.Number & " " & err.Description
End If
Resume Exit_Form_Current

End Sub

does the Exit Sub cause the routine to never hit the End Sub? or only when there is an error?
 
J

John W. Vinson

Hello All

i have this:

Private Sub Form_Current()
On Error GoTo Err_Form_Current

Call Visibility

Exit_Form_Current:
Exit Sub

Err_Form_Current:
If err = 2448 Then
Else
MsgBox "Error #: " & err.Number & " " & err.Description
End If
Resume Exit_Form_Current

End Sub

does the Exit Sub cause the routine to never hit the End Sub? or only when there is an error?

End Sub isn't executable.

Exit Sub does exactly that - exits the subroutine, immediately.

What's happening (or not happening) that you expect? What is "Visibility"?
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/Forums/en-US/accessdev/
http://social.answers.microsoft.com/Forums/en-US/addbuz/
and see also http://www.utteraccess.com
 
V

Vacuum Sealed

Hi

The If statement doesn't look right in that you step straight from
"Then" to "Else" with no action before moving onto the Else option.

Exit_Form_Current:
Exit Sub

Err_Form_Current:
If err = 2448 Then
MsgBox "Holy Crap Batman, It's a 2448 Error"
Else
MsgBox "Error #: " & err.Number & " " & err.Description
End If
Resume Exit_Form_Current

End Sub

HTH
Mick.
 
J

John W. Vinson

Hi

The If statement doesn't look right in that you step straight from
"Then" to "Else" with no action before moving onto the Else option.

Exit_Form_Current:
Exit Sub

Err_Form_Current:
If err = 2448 Then
MsgBox "Holy Crap Batman, It's a 2448 Error"
Else
MsgBox "Error #: " & err.Number & " " & err.Description
End If
Resume Exit_Form_Current

End Sub

HTH
Mick.

<shrug> Neither code block of an IF - THEN - ELSE - END IF construct is
required. You could, if you prefer, use

If Err <> 2448 Then
MsgBox "...
End If

But you can certainly use

If <expr> Then
Else
End If

with no action in either block (though of course this would be a silly
do-nothing), or with code in either or both blocks.
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/Forums/en-US/accessdev/
http://social.answers.microsoft.com/Forums/en-US/addbuz/
and see also http://www.utteraccess.com
 
D

DawnTreader

End Sub isn't executable.

Exit Sub does exactly that - exits the subroutine, immediately.

What's happening (or not happening) that you expect? What is "Visibility"?
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/Forums/en-US/accessdev/
http://social.answers.microsoft.com/Forums/en-US/addbuz/
and see also http://www.utteraccess.com

Hello

Call Visibility is just routine for changing availablilty of fields based on various data in the loaded form.

i always thought that the exit form current only happened when there was an error and that unless there was it would just move to the end of the sub and "exit" at the end sub.

i was following a bit of code execution and it went to the exit sub unexpectedly. there wasnt anything wrong per se, just an unexpected path of execution.

you learn something new everyday... :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top