Results 1 to 4 of 4
  1. #1
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328

    VBA public procedure in a form

    I had thought that if a procedure or function is designated as Public in code associated with a form, that other forms could activate the procedure or function as long as the form holding the public function was open. I am getting a" not defined" message when I try it.



    very very simplified, here is basically what I am doing.
    Form1:
    Private Sub Command0_Click()
    TEST ("message")
    End Sub

    Form2:
    Public Function TEST(Z)
    MsgBox Z
    End Function

    I am using a2007 with w7. What am I missing?

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    That would work if you put the Public function in a standard module instead of a Form module. It actually becomes a Method of the Form so you can use the Forms collection with:
    Forms.YourFormName.TEST("message")

  3. #3
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328
    Thanks much, again. It somehow got into my head that "public" made the code accessible in the same way that modules are accessible.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You're welcome. Are you ready to follow the link in my sig and mark this thread as Solved?

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Public Terminal Emulation
    By pkstormy in forum Code Repository
    Replies: 0
    Last Post: 08-31-2010, 02:09 AM
  2. Replies: 1
    Last Post: 04-13-2010, 12:18 PM
  3. Pass a form property to a procedure
    By trb5016 in forum Programming
    Replies: 2
    Last Post: 02-17-2010, 04:15 PM
  4. public instead of dim not working
    By DKY in forum Access
    Replies: 1
    Last Post: 10-14-2008, 11:42 AM
  5. stored procedure return value to access form
    By rbw940 in forum Programming
    Replies: 0
    Last Post: 10-13-2008, 01:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums