+ Reply to Thread
Results 1 to 4 of 4

Thread: How to call a Module with antother Module in VBA!

  1. #1
    chris s.
    Join Date
    May 2010
    Posts
    107
    Points
    1
    Answers Provided
    0


    0

    Default How to call a Module with antother Module in VBA!

    Hi!

    What I am looking for is very basic. I have a project containing two modules. Now I want to call one module by the other module. What I mean is I want the second module to be executed by the first module. I thought the "call" command would be the right way to do but I always get an error message. I also tried writing in brackets ("Process1") but this didnt work as well. Any suggestion what command to use? Has this something to do with private and public subs?

    Private Sub Testprocess()

    Dim pMxDoc As IMxDocument
    Dim pFeatLayer As IFeatureLayer
    Dim pFeatureClass As IFeatureClass
    Dim pFeatureCursor As IFeatureCursor
    Dim pField As IField
    Dim pFeature As IFeature
    Set pMxDoc = ThisDocument
    Set pFeatLayer = pMxDoc.FocusMap.Layer(0)
    Set pFeatureClass = pFeatLayer.FeatureClass
    Set pFeatureCursor = pFeatureClass.Search(Nothing, False)
    Set pFeature = pFeatureCursor.NextFeature
    Dim n As Integer

    Dim pProcessID As Integer

    Do Until pFeature Is Nothing
    pProcessID = pFeature.Value(pFeature.Fields.FindField("Process_ID"))
    If (pProcessID = 1) Then

    Call Process1


    Else: End If

    Set pFeature = pFeatureCursor.NextFeature
    Loop

    End Sub

    Thanks for your help

  2. #2
    Jun Folledo
    Join Date
    May 2010
    Posts
    2
    Points
    0
    Answers Provided
    0


    0

    Default Re: How to call a Module with antother Module in VBA!

    yes, if a Sub or Function is declared as Private in another module, you cannot call it from another module. You can call it only on the same module.

  3. #3
    Ruchira Welikala
    Join Date
    May 2010
    Posts
    118
    Points
    0
    Answers Provided
    0


    0

    Default Re: How to call a Module with antother Module in VBA!

    Just make the Declaration of the procedures (subs) public. It should look something like this:


    Code:
    Public Sub Testprocess()
    
    Dim pMxDoc As IMxDocument
    Dim pFeatLayer As IFeatureLayer
    Dim pFeatureClass As IFeatureClass
    Dim pFeatureCursor As IFeatureCursor
    Dim pField As IField
    Dim pFeature As IFeature
    Set pMxDoc = ThisDocument
    Set pFeatLayer = pMxDoc.FocusMap.Layer(0)
    Set pFeatureClass = pFeatLayer.FeatureClass
    Set pFeatureCursor = pFeatureClass.Search(Nothing, False)
    Set pFeature = pFeatureCursor.NextFeature
    Dim n As Integer
    
    Dim pProcessID As Integer
    
    Do Until pFeature Is Nothing
    pProcessID = pFeature.Value(pFeature.Fields.FindField("Process_ ID"))
    If (pProcessID = 1) Then
    
    Call Process1
    
    
    Else: End If
    
    Set pFeature = pFeatureCursor.NextFeature
    Loop
    
    End Sub
    Ruchira Welikala | GIS Specialist
    MMM Group Inc.

  4. #4
    chris s.
    Join Date
    May 2010
    Posts
    107
    Points
    1
    Answers Provided
    0


    0

    Default Re: How to call a Module with antother Module in VBA!

    Hi!

    Thanks. I figured it out

    Best regards
    Chris

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts