Results 1 to 8 of 8
  1. #1
    Paowtrick is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Nov 2018
    Posts
    10

    When to use modules?

    First of im a beginner.
    So ive been building a DB for a while now, and start to notice some codes I have to type over and over again. Some places i have 6-7 rows of code in three places on the same form. So it starts to build up unnecessary much. So I read about modules, and I think that they are possible to store repeating codes and call them when I need? So if anyone could help me keep a cleaner code.



    And I appreciate if any one knows a good forumpost or article or youtube clip I should check out to learn some more about good structure, to make it "future proof".

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    i separate my functions,
    modFilesys has all my file functions; MakeDir, DoesFileExist...etc
    modGLOBE has all my global definitions
    modUSER has all user operations; getUserID, getUserName, etc
    modAPP used for custom ops for the app itself. Usu different for every app.

    it just lets me find things easier.

  3. #3
    Minty is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,159
    In addition to Ranmans suggestions for storing globally used functions, If the code you refer to is very form specific you can create a Private Sub in the forms code module, and call it repeatedly whenever you need it rather than repeating it. e.g. lets say you needed something like this very simplified example to run on lots of different events;

    Code:
    Private Sub SetButtonsUp()        
       Me.txtBox1.Visible = False
       Me.txtBox2.Visible = False
       Me.txtBox3.Visible = True
       Me.txtBox4.Visible = True
    
    
    End Sub
    Then simply in all the places you want to use it on the form ;

    Code:
    Call SetButtonsUp
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  4. #4
    Paowtrick is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Nov 2018
    Posts
    10
    uff, I feel like I need to read up ALOT more, I did not understand any of the functions
    I will try that call thing out though.

    edit: is this something to have as a function
    Code:
    If Dirty = True Then Dirty = False
    and then use call dirty?

  5. #5
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    I erase all the ISDIRTY code.
    its of no use and not backwards compatible.

  6. #6
    Paowtrick is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Nov 2018
    Posts
    10
    oh, I use isdirty on every single "after update" to get the results of the change. Should I do something else?

  7. #7
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    The "Dirty" property is an indication if there are unsaved changes to a form. (NOT the form design - just data!)

    Nothing wrong with using it.
    In my code, I use this
    Code:
    If Me.Dirty Then 
      Me.Dirty = False
    End If

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Quote Originally Posted by ranman256 View Post
    I erase all the ISDIRTY code.
    its of no use and not backwards compatible.
    I'm also curious about this. I use the same code Steve does, though for me it's a very rare case of me using one-line format:

    If Me.Dirty Then Me.Dirty = False
    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. Forgotten How To Add To All Modules
    By Whale in forum Programming
    Replies: 3
    Last Post: 11-11-2016, 06:25 PM
  2. When to use standard modules vs. class modules
    By Access_Novice in forum Programming
    Replies: 7
    Last Post: 01-03-2016, 10:47 PM
  3. Passing a value between modules
    By NISMOJim in forum Programming
    Replies: 3
    Last Post: 07-19-2013, 12:34 PM
  4. What is the point of different modules?
    By cowboy in forum Programming
    Replies: 3
    Last Post: 03-29-2010, 10:43 PM
  5. How to use Modules
    By wasim_sono in forum Access
    Replies: 0
    Last Post: 01-16-2007, 06:29 AM

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