Results 1 to 4 of 4
  1. #1
    orcinus is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Apr 2010
    Posts
    67

    Calling A Module Function To Open A Form

    I would like to create a function in a module that can be used to open a form from another form. So, in my module, I have:



    Public Function fcn_opn_frm(str_frm As String)

    Dim frm As Form
    Set frm = Forms(str_frm)
    DoCmd.OpenForm frm, acNormal

    End Function

    Then I have a command button in a form which is supposed to open another form. This has code thus:

    Private Sub cmd_opn_frm_work_Click()
    Call fcn_opn_frm(frm_data_work)
    End Sub

    But it doesn't work. I get a 'Variable Not Defined' error which highlights the 'frm_data_work' in the command button code.

    Where am I going wrong? Also, I understand I don't have to do it this way, but am always looking for alternative ways to do things in Access as this invariably expands my knowledge of how to do stuff in general..

    Thanks for any assistance..!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    The name of the form needs to be in quotes (it's a string).

    I'd simply use that in the OpenForm and drop the rest (in the function).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    orcinus is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Apr 2010
    Posts
    67
    Quote Originally Posted by pbaldy View Post
    The name of the form needs to be in quotes (it's a string).

    I'd simply use that in the OpenForm and drop the rest (in the function).
    ok, I see, thanks, that works..its the little things!

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 3
    Last Post: 08-13-2010, 11:23 PM
  2. calling function
    By ManvinderKaur in forum Programming
    Replies: 3
    Last Post: 07-22-2010, 10:53 PM
  3. Track form and module design changes
    By c_smithwick in forum Modules
    Replies: 0
    Last Post: 05-11-2010, 10:28 AM
  4. search,view and open function
    By blurboy84 in forum Reports
    Replies: 0
    Last Post: 10-08-2009, 11:42 PM
  5. Calling a function and returning a value
    By 3dmgirl in forum Programming
    Replies: 0
    Last Post: 04-23-2007, 02:20 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