Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / October 2004

Tip: Looking for answers? Try searching our database.

defining label

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tom - 04 Oct 2004 22:13 GMT
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.
Tim Ferguson - 05 Oct 2004 09:19 GMT
"Tom" <anonymous@discussions.microsoft.com> wrote in news:20dd01c4aa56
$fb36abb0$a501280a@phx.gbl:

>   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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.