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

    Calling a module??

    Hi and thanks for your help
    I have a form "Lots"
    in the Lots Form I have a

    Private sub L-SitingArea_AfterUpdate()


    If Me.L_SitingArea = "CESSNOCK_DCP" Then ##NEED HELP HERE## i want to call a module called read_CESSNOCK_DCP_DUPLEX
    If Me.L_SitingArea = "NSW_GREENFIELD_CDC" Then Call read_NSW_GREENFIELD_CDC
    If Me.L_SitingArea = "HUNTLEE_DCP" Then Call read_HUNTLEE_DCP
    If Me.L_SitingArea = "LAKEMAC_DCP" Then Call read_LAKEMAC_DCP
    If Me.L_SitingArea = "MAITLAND_DCP" Then Call read_MAITLAND_DCP
    If Me.L_SitingArea = "SINGLETON_DCP" Then Call read_SINGLETON_DCP
    If Me.L_SitingArea = "CENTRAL_COAST_DCP" Then Call read_CENTRAL_COAST_DCP
    If Me.L_SitingArea = "PORTSTEPHENS_DCP" Then Call read_PORTSTEPHENS_DCP
    If Me.L_SitingArea = "NEWCASTLE_DCP" Then Call read_NEWCASTLE_DCP
    End Sub

    However all the read_SUBS are on the same page, I want to create modules for each read_Sub, (easier to manage for updating or deleting) but I don't know how to call the module

    With thanks
    Craig

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    IIRC, it's just modulename.procedurename
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    CraigR is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    27
    module = Cessnock_DUPLEX
    private sub = read_CESSNOCK_DCP_DUPLEX()

    so would it be??

    If Me.L_SitingArea = "CESSNOCK_DCP" Then Cessnock_DUPLEX.read_CESSNOCK_DCP_DUPLEX()

  4. #4
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    The underlining is a bit confusing and maybe obscuring but I'll say yes. Easy enough to try, no?
    You originally stated you want to "call" a module. You can't but you can call a procedure in it.

  5. #5
    CraigR is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    27
    sorry, yes call a procedure

    so the module is called = Cessnock
    the procedure is Private Sub read_Cessnock_Duplexes

    The procedure on form.Lots is
    Private sub L-SitingArea_AfterUpdate()
    ( module ).( procedure )
    If Me.L_SitingArea = "CESSNOCK_DCP" Then call Cessnock.read_Cessnock_Duplexes 'is this correct?

    If Me.L_SitingArea = "NSW_GREENFIELD_CDC" Then Call read_NSW_GREENFIELD_CDC
    If Me.L_SitingArea = "HUNTLEE_DCP" Then Call read_HUNTLEE_DCP
    If Me.L_SitingArea = "LAKEMAC_DCP" Then Call read_LAKEMAC_DCP
    If Me.L_SitingArea = "MAITLAND_DCP" Then Call read_MAITLAND_DCP
    If Me.L_SitingArea = "SINGLETON_DCP" Then Call read_SINGLETON_DCP
    If Me.L_SitingArea = "CENTRAL_COAST_DCP" Then Call read_CENTRAL_COAST_DCP
    If Me.L_SitingArea = "PORTSTEPHENS_DCP" Then Call read_PORTSTEPHENS_DCP
    If Me.L_SitingArea = "NEWCASTLE_DCP" Then Call read_NEWCASTLE_DCP
    End Sub

  6. #6
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Remove the word "Private" from the procedures that you want to call, or replace it with the word "Public". So, you don't need to include the name of module, just call the procedure by its name.

    Additional, in your case, maybe it's much better to say:
    Code:
    Application.Run "read_" & Me.L_SitingArea
    Just this!

  7. #7
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Code:
    
    If Me.L_SitingArea = "NSW_GREENFIELD_CDC" Then Call read_NSW_GREENFIELD_CDC
            If Me.L_SitingArea = "HUNTLEE_DCP" Then Call read_HUNTLEE_DCP
            If Me.L_SitingArea = "LAKEMAC_DCP" Then Call read_LAKEMAC_DCP
            If Me.L_SitingArea = "MAITLAND_DCP" Then Call read_MAITLAND_DCP
            If Me.L_SitingArea = "SINGLETON_DCP" Then Call read_SINGLETON_DCP
            If Me.L_SitingArea = "CENTRAL_COAST_DCP" Then Call read_CENTRAL_COAST_DCP
            If Me.L_SitingArea = "PORTSTEPHENS_DCP" Then Call read_PORTSTEPHENS_DCP
            If Me.L_SitingArea = "NEWCASTLE_DCP" Then Call read_NEWCASTLE_DCP
    That's not what I wrote in post 2 and not what you wrote in your reply.
    First, I do not think the procedure to be called can be Private but needs to be Public.
    Second, drop the Call keyword. While it may work for you, I did not use it and it introduces the potential for raising a syntax error, depending on whether or not the called procedure is a function that returns a value.

    Lastly, I would write
    If Me.L_SitingArea = "NSW_GREENFIELD_CDC" Then Cessnock.read_Cessnock_Duplexes
    Not real important, but an alternative to a buch of IFs is a Select Case block, such as
    Code:
    Select Case Me.L_SitingArea
      Case "NSW_GREENFIELD_CDC" 
        Cessnock.read_NSW_GREENFIELD_CDC
    
      Case "HUNTLEE_DCP" 
        Cessnock.read_HUNTLEE_DCP
      etc
        etc
    
    End Select
    Make sure you understand how Select Case works before using it

  8. #8
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Quote Originally Posted by accesstos View Post
    Remove the word "Private" from the procedures that you want to call, or replace it with the word "Public". So, you don't need to include the name of module, just call the procedure by its name.
    I have seen that syntax fail in older databases, but I cannot recall for sure if their procedures were private or not. In fact, just recently I had a job where a 2003 db wouldn't compile until I added the module name, yet it ran for them. When I look at the code, I wonder how it ran at all. So for this problem, I figured no harm in using an explicit reference.

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

Similar Threads

  1. Calling a module into a form
    By CraigR in forum Modules
    Replies: 3
    Last Post: 12-12-2018, 08:04 PM
  2. Replies: 5
    Last Post: 11-25-2017, 03:45 AM
  3. Replies: 3
    Last Post: 12-17-2015, 10:46 AM
  4. Calling A Module Function To Open A Form
    By orcinus in forum Modules
    Replies: 3
    Last Post: 09-29-2010, 04:43 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