defining label

T

Tom

Hello there

I have a subroutine which has vba code. But the issue
is if i want to run another code (from a diffrent form)
from that subroutine, how i can do that. One way is that i
write the label name in the main subroutine

e.g. Following is the main subroutine
Dim varX As Variant
If Len(Nz(Forms![output print selection]!P_Name, "")) = 0
Then
varX = DLookup("[F_Flag]", "Flag Support")
Else
varX = DLookup("[F_Flag]", "Flag Support", "[P_Name]
='" & Forms![output print selection]!P_Name & "'")
End If

If varX = 0 Then

Else
MsgPrint2 = "Please run the calculation engine first!"
MsgBox MsgPrint2, style, Title
GoTo Exit_Command70_Cl


MsgBox MsgPrint2, style, Title
GoTo Exit_Command70_Click



Now if i want to call another subroutine which is in a
diffrent form than i can write a code like

(the above code would remain the same just last couple of
line changes as follows

If varX = 0 Then

Else

GoTo Exit_Command35_Click


Now if i do that, it shows the error that label is not
defined. How can i define a label which is in a diffrent
form and diffrent subroutine.

I would appreciate if somebody woulc help me on the issue.

Thank you.
 
T

Tim Ferguson

if i want to run another code (from a diffrent form)
from that subroutine, how i can do that.

You call a procedure -- note that the other form must be open and the
procedure in the other form must be specified as Public:-

' explicit, easier to read
If varX <> 0 Then Call OtherForm.DoSomething

or

' functionally identical
If varX <> 0 Then OtherForm.DoSomething

or

' function call rather than sub
If varX <> 0 Then varX = OtherForm.ReturnSomething


Using GoTo with line numbers or labels is ugly and generally deprecated,
with the exception of local error handling because VB does not offer
anything better. There is a stack of research from the sixties and early
seventies showing that properly-implemented modular programming can
achieve everything that spaghetti programming could, only better.

The bottom line, Just Don't Do It.

Hope that helps


Tim F
 

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