Results 1 to 4 of 4
  1. #1
    EddieN1 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2011
    Posts
    313

    Using "Include" or "Copy" in VBA

    In some other languages, you can put a directive in the code that copies code from another module. For example, in COBOL you have a COPY statement. I think C++ uses the "Include" statement to do something similar.

    If you have code that is common to multiple modules, you can create the code in an external text file, then use the "copy" directive to bring it into your module. This allows you to make a change one time in the "copy" text file and have it automatically included in all the modules that use this common code.

    I know that in many cases you can accomplish this by putting it in a Public function. However, in my case, the "common" code refers to updating controls in a Form and, therefore, needs to be located in each Form's module.



    Any help would be appreciated.

    Thanks, Eddie

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Maybe this will help http://www.mrexcel.com/forum/showthread.php?t=75489

    What is it that is being 'updated' on the controls?
    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
    EddieN1 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2011
    Posts
    313
    I have 9 forms that present different data elements of the same table. The data elements may appear on multiple forms. When selected fields change, I recalculate and update other data elements. I update the control Me.Field01 where Field01 is linked to the data element Field01 in the table. I developed and tested the update subroutines in Form1 and would like to "duplicate" the same logic in Forms 2-9. I could copy and paste the logic in the other 8 forms. However, as time goes on, if I decide to modify one of the update subroutines, I don't want to have to copy and paste again. I would like to create a text file, called something like "UpdateRoutines.txt" with all the Update logic. In each of the 9 forms, I'd like to be able to put in a "copy UpdateRoutines.txt" directive which says "use UpdateRoutines.txt" here. In COBOL, this is accomplished by "Copy UpdateRoutines.txt". In C++, they use an "Include" statement. etc. Does VBA have a comparable technique?

    Eddie

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Still don't understand. You state forms have different data elements but then say the data elements may appear on multiple forms. Do you want to provide project for analysis?
    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.

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

Similar Threads

  1. Replies: 2
    Last Post: 11-04-2011, 02:45 AM
  2. Replies: 8
    Last Post: 08-05-2011, 02:55 PM
  3. Replies: 16
    Last Post: 07-22-2011, 09:23 AM
  4. ComboBox "Select" and "DLookUp"
    By witooldas in forum Forms
    Replies: 0
    Last Post: 03-23-2011, 03:31 AM
  5. "Group By" causes "ODBC--Call Failed" error
    By kaledev in forum Queries
    Replies: 1
    Last Post: 03-09-2011, 02:43 PM

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