Results 1 to 4 of 4
  1. #1
    CraigR is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    27

    Post Module for multiple forms

    Hi and thank you for any help

    I have a form that calls a module

    Form is called "Lots"

    Private Sub L_SitingArea_AfterUpdate()


    If Me.L_SitingArea = "CESSNOCK_DCP" Then DCPcessnock.read_CESSNOCK_DCP

    The Module is called DCPcessnock
    and the Public Sub is called read_CESSNOCK_DCP
    This works fine, thanks for previous help!

    I have a second form called "LotsQInput" which I would also like to call the module.

    However the module is written as follows

    Public Sub read_CESSNOCK_DCP() 'NSW CESSNOCK COUNCIL DCP

    If Forms("Lots").L_SitingArea = "CESSNOCK_DCP" Then
    Forms("Lots").PODLotType1.Visible = False
    Forms("Lots").PODLotType.Visible = False
    Else
    Forms("Lots").PODLotType1.Visible = False
    Forms("Lots").PODLotType1.Visible = False
    End If


    The same field names are on BOTH forms "Lots" & "LotsQInput"

    How do I change: If
    Forms("Lots"). to be multiple Forms


    Like If Forms ("Lots" or "LotsQInput") how do I allow the module respond to multiple forms?


    Thanks
    Craig


  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,816
    Send the form name to the procedure as an argument.

    Public Sub read_CESSNOCK_DCP(strForm As String)

    Then reference the form with variable.

    If Forms(strForm).L_SitingArea = "CESSNOCK_DCP" Then

    Call the procedure:
    read_CESSNOCK_DCP(Me.Name)

    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I do the same thing as June7, but a little different. The results are the same.

    The Module code would be:
    Code:
    Public Sub read_CESSNOCK_DCP(TheForm As Form)    'NSW CESSNOCK COUNCIL DCP
        If TheForm!L_SitingArea = "CESSNOCK_DCP" Then
            TheForm!PODLotType1.Visible = False
            TheForm!PODLotType.Visible = False
        Else
            TheForm!PODLotType1.Visible = True
            TheForm!PODLotType.Visible = True
        End If
    End Sub
    To call the procedure:
    Code:
    Private Sub Command5_Click()
        Call read_CESSNOCK_DCP(Me)
    End Sub

    ---------------------------------------------------------------------

    I am curious: Is you code really like this:
    Code:
    If Forms("Lots").L_SitingArea = "CESSNOCK_DCP" Then
        Forms("Lots").PODLotType1.Visible = False
        Forms("Lots").PODLotType.Visible = False    '<< All options are FALSE???
    Else
        Forms("Lots").PODLotType1.Visible = False    '<< Same Control name???
        Forms("Lots").PODLotType1.Visible = False    '<< Same Control name???
    End If

    Good luck with your project...

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    It's just my programming style, but I do the same as Steve - reason is 'TheForm' might be a subform or I might have multiple instances of the form open at the same time

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

Similar Threads

  1. Replies: 4
    Last Post: 02-09-2015, 10:16 AM
  2. Replies: 5
    Last Post: 05-09-2014, 08:12 AM
  3. Replies: 7
    Last Post: 02-26-2013, 02:26 PM
  4. Replies: 4
    Last Post: 05-16-2011, 04:58 PM
  5. Replies: 2
    Last Post: 05-25-2010, 02:45 PM

Tags for this Thread

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