Results 1 to 5 of 5

Thread: how to make a function available for all forms ?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    66

    how to make a function available for all forms ?

    Hi ,
    i have defined a sub called permission,
    i want to make it global over the whole project, so in any form i can write
    VB Code:
    1. call permission
    it will call it without defining it in every form, do i have to make global ??

  2. #2
    Member
    Join Date
    Mar 2004
    Location
    Computer
    Posts
    56

    Re: how to make a function available for all forms ?

    Instead of this:
    Code:
    Private Sub Permission()
    End Sub
    This:
    Code:
    Public Sub Permission()
    End Sub
    ~!~Computer Nerd~!~

  3. #3
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: how to make a function available for all forms ?

    You must put it in a module though : )

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: how to make a function available for all forms ?

    Almost but you need to declare it only once in a standard Module because if you do it that way you need to reference it by calling the form name first.

    Call Form2.Permission

    Vs Call Permission


    VB Code:
    1. 'In a module (Module1.bas)
    2. Option Explicit
    3.  
    4. Public Function Pemission()
    5.     MsgBox "I am in a Module that can be called from anywhere throughout this project! D"
    6. End Sub
    7.  
    8.  
    9. 'Behind any form in your project.
    10. 'Invoke from any procedure but for ex. its a command button click
    11. Option Explicit
    12.  
    13. Private Sub Command1_Click()
    14.     Call Permissions
    15. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: how to make a function available for all forms ?

    ...and the proper place for that sub is in a code module and not a form. Subs created in a code module are public by default and while if the sub is in Form1 you would have to call Form1.Permission from Form2, if it's in the code module you just have to do Call Permission, or simply Permission.

Posting Permissions

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



Click Here to Expand Forum to Full Width