Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2003

    Unanswered: using Forms inside Module subroutines

    I would like to have a general utils module, consisting of several methods that will generically work on any form passed to it. These modules will be called on by form event handlers.
    My first attempt was to pass the form in as a parameter. This would be my most preferred method if I could get it to work. The module method signature looked like:

    Public Sub LoadRecord(ByVal form As Form)

    and the event handler simply consisted of one line:

    DBUtils.LoadRecord(me) or DBUtils.LoadRecord(Form)

    When I ran the code, I got a type mismatch error.

    So then my second method was to pass in the form name to the module, and have the module look it up. So the module looked like:

    Public Sub LoadRecord(ByVal form As String)
    Dim myForm As Form
    myForm = Forms(formName)
    End Sub

    However, the compiler issues "An invalid use of property" on the second line.

    So now, I just use Forms(formName) inside LoadRecord whenever I need access to the form. This works, but it appears inefficient as it would performing a form lookup each time I need access to a form.
    Any suggestions on how to get the first two examples working?
    Thanks so much.

  2. #2
    Join Date
    Aug 2003
    I thing that in the second example Replace the sentence
    myForm = Forms(formName)
    myForm = Forms!formName <--------- real name
    or use this one

    myForm = Forms(integer).Name

  3. #3
    Join Date
    Oct 2003

    Using myForm = Forms!formName does not work. I believe with the explanation, formName has to be the hard coded form name, which doesn't apply in my case since formName would be a parameterized string.

    After further research, I was able to get my 2nd preferred method to work using:

    Set myForm = Forms(formName)

    Still open to suggestions on how to get my top preferred method to work. The following attempt does not work...

    module code:
    Public Sub LoadRecord(ByRef form As Form)

    event handler code:


Posting Permissions

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