Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2008
    Posts
    10

    Unanswered: Passing FORM data fromone module to Another

    Hello All, I hope someone can help me out.

    I am developing several forms to input data. The information is divided into subcategories. The user choose a type of object and the sub categories become visable and move on the form base on type. this is very easy and I am using the following code.

    With [Form]![exampleformname]![position1object]
    .Visible = True
    .Top = 1.667
    .Left = 0.125

    Now there are several forms and I would like to reuse the code.

    I have position1, position2, ...etc and NotUsed1, NotUsed2 (visible = false)


    I have written a module that has all the positions defined

    Public Sub FirstPosition(ByRef strFormName As String, ByRef strLabelPosition1 As String, ByRef strTextBoxPosition1 As String)

    With [Forms]!strFormName!strLablePosition1
    .Visible = True
    .Top = 1.6667
    .Left = 0.125
    .TabStop = True
    End With

    With [Forms]!strFormName!strTextBoxPosition1
    .Visible = True
    .Top = 1.6667
    .Left = 1.7396
    .TabStop = True
    .TabIndex = 4
    .SetFocus
    End With

    End Sub

    The sub is called from inside the form being used and I define the strFormName and strTextBoxPosition 1 and 2 (Example strFormName = "[ComponentCapacitors_Form]" I do the same with object.


    I must be getting the formating wrong.

    How do you pass the name of FOrms, reports to a module so they can change the object properties inside another module.


    If I made you confused I am sorry. This must me a simple trick and just getting it wrong.

    Thanks

    Dale

  2. #2
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    to pass a form object as argument:

    dim oForm as Form
    set oForm = me
    mySub oForm
    set oForm = nothing

    public mySub(byref someForm as Form)
    With someForm
    ...

    (yes - i know byref is default)

    izy
    currently using SS 2008R2

  3. #3
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Probably should have a look at ActiveForm too. I often use this to have global code work differently depending upon which screen is active at the time.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  4. #4
    Join Date
    Oct 2008
    Posts
    10
    Ok

    If a write

    In my form module
    Case CapacitorType
    Case = “Ceramic”
    Position1 TextBox1
    Position2 TextBox2
    End Case
    In my public module

    Public Sub Position1 (WHAT DO I PUT HERE IF I WANT A OBJECT FROM MY FORM MODULE {TextBox1} )
    Dim frmCurrentForm As Form
    Set frmCurrentForm = Screen.ActiveForm

    With frmCurrentForm!{WHAT GOES HERE (TextBox1)}
    .Visible = True
    .Top = 2400.048
    .Left = 180
    End With

    I see how to set the form, but the object that I want to set the properties on I do not get how to send it to the public module


    Thanks
    Dale
    Last edited by rogerdalebrown; 11-03-08 at 00:09.

  5. #5
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    There is also a forms() collection that is a member of the application object

    You can pass in a string representing your form name and later get a reference to it with:


    Application.Forms("someFormName")
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  6. #6
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    I'd be trying something like this:

    Code:
    Case CapacitorType
       Case = "Ceramic"
          Position1 "TextBox1"
          Position2 "TextBox2"
       etc...
    End Case
    
    
    Public Sub Position1 (ControlName as String)    
         With Screen.ActiveForm.Controls(ControlName)
              .Visible = True
              .Top = 2400.048
              .Left = 180
         End With
    End Sub
    Or something along those lines.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

Posting Permissions

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