Results 1 to 9 of 9

Thread: Call procedures

  1. #1
    Join Date
    Mar 2004
    Posts
    287

    Unanswered: Call procedures

    I have always programmed databases to use the code within their own forms, queries but now would like to create a method using Modules.

    I have a check I need to do multiple times on one form and thus would like to create a module as below;

    Code:
    Public Sub CompleteMarketingCheck(varTo As Variant)
    
    If [MarketInductionNA] = False And [MarketInduction] = True Then
        If [MarketPhotoNA] = False And [MarketPhoto] = True Then
            If [MarketWebsiteNA] = False And [MarketWebsite] = True Then
                [MarkComplete] = True
                [LabelCompleted].Visible = True
                Else
                [MarkComplete] = False
                [LabelCompleted].Visible = False
                End If
            End If
    End If
    Forget what the code actually does for now...

    From my understanding I only need to call this module from the form thus;

    Code:
    Call CompleteMarketingCheck
    But this doesn't appear to be working. I have attempted to solve this problem using the forums and internet but can not - can anyone help please?

    Thanks.

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Sounds like you want a function
    Code:
    Public Function functionName(param1, param2)
    and how to call it
    Code:
    functionName value1, value2
    EDIT: If this is specific to one form then use Private Function
    George
    Home | Blog

  3. #3
    Join Date
    Mar 2004
    Posts
    287
    but how does (param1, param2) allow me to call the sub procedure (Module)?

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Code:
    Private Function CompleteMarketingCheck(varTo As Variant)
    
    If [MarketInductionNA] = False And [MarketInduction] = True Then
        If [MarketPhotoNA] = False And [MarketPhoto] = True Then
            If [MarketWebsiteNA] = False And [MarketWebsite] = True Then
                [MarkComplete] = True
                [LabelCompleted].Visible = True
                Else
                [MarkComplete] = False
                [LabelCompleted].Visible = False
                End If
            End If
    End If
    the above highlight appears to be an unused parameter - any reason why it's there? Anyhow, try one of the following once you've made the change from sub to function.
    Let us know the result!
    Code:
    CompleteMarketingCheck()
    '--Or
    Call CompleteMarketingCheck()
    George
    Home | Blog

  5. #5
    Join Date
    Mar 2004
    Posts
    287
    damn can't belivee i missed that - thanks, all works well now.

    just a quick wuestion - if i want to include extra lines to code, in other words its too long for one line how do i do this please?

  6. #6
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Using strings...
    Code:
    Msg = "here is one example "
    Msg = Msg & "with 2 lines"
    
    Msg = "here is another example " & _
          "using 2 lines too"
    George
    Home | Blog

  7. #7
    Join Date
    Mar 2004
    Posts
    287
    ok but i have this piece of code and it appears it dosn't want to work due to the linage?

    Code:
    If [Forms]![Main]![SubPersonnel]![PersDocSent] = True And [Forms]![Main]![SubPersonnel]![PersDocRet] = True And [Forms]![Main]![SubPersonnel]![PersRef1] = True And [Forms]![Main]![SubPersonnel]![PersRef2] = True And [Forms]![Main]![SubPersonnel]![PersNewEmplSent] = True And [Forms]![Main]![SubPersonnel]![PersNewEmplRet] = True & _
        [Forms]![Main]![SubPersonnel]![PersFile] = True And [Forms]![Main]![SubPersonnel]![PersProbation] = True And [Forms]![Main]![SubPersonnel]![PersID] = True And [Forms]![Main]![SubPersonnel]![PersEmailMan] = True And [Forms]![Main]![SubPersonnel]![PersIndSetup] = True And [Forms]![Main]![SubPersonnel]![PersManuals] = True & _
        [Forms]![Main]![SubPersonnel]![PersHRSoftware] = True And [Forms]![Main]![SubPersonnel]![PersListTele] = True And [Forms]![Main]![SubPersonnel]![PersListStaff] = True And [Forms]![Main]![SubPersonnel]![PersListLines] = True And [Forms]![Main]![SubPersonnel]![PersFire] = True And [Forms]![Main]![SubPersonnel]![PersFloorplans] = True & _
        [Forms]![Main]![SubPersonnel]![PersBDay] = True And [Forms]![Main]![SubPersonnel]![PersMedical] = True And [Forms]![Main]![SubPersonnel]![PersPolicy] = True And [Forms]![Main]![SubPersonnel]![PersHRInduction] = True And [Forms]![Main]![SubPersonnel]![PersFeedback] = True Then
        [Forms]![Main]![SubPersonnel]![PersComplete] = True
        Else
        [Forms]![Main]![SubPersonnel]![PersComplete] = False
    End If
    Alternatively would it be better (faster) to add Dims with the links on and then just say if link1 = true and link2 = true then... etc etc

  8. #8
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Remove the ampersands (&) - they are used for concatenation.
    George
    Home | Blog

  9. #9
    Join Date
    Mar 2004
    Posts
    287
    thanks. all works now.

Posting Permissions

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