Results 1 to 8 of 8
  1. #1
    mchadwick is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Posts
    71

    Run a Module


    I have a module I have created and I have no idea how to run it from a macro. I simply named it module1

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    You don't run the module, you run a function contained within the module (and they can't have the same name). The macro action would be RunCode.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    mchadwick is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Posts
    71
    Okay, what do I put in the "function Name" box? apparently I did not give it a name and Im not sure how to.

  4. #4
    mchadwick is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Posts
    71
    This is what I am trying to get to run. I pasted this into the module. General on drop down to the left and command0_click on the right one.


    Private Sub Command0_Click()
    Dim InputDir, ImportFile As String, tblName As String
    InputDir = "C:\Import_Export\To_Import\"
    ImportFile = Dir(InputDir & "\*.csv")
    Do While Len(ImportFile) > 0
    'tblName = Left(ImportFile, (InStr(1, ImportFile, ".") - 1)) 'This is to import each file into single tables.
    tblName = "MidOhio BAC Import" 'This is to import all files into one table.
    DoCmd.TransferText acImportDelim, , tblName, InputDir & ImportFile, True
    ImportFile = Dir
    Loop

    End Sub

  5. #5
    mchadwick is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Posts
    71
    Let me explain what I am trying to do. I have several csv files that are going to be imported on a daily basis. Each files has a name that includes the date. I want to import each csv into its own table.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    You have that in a standard module? Change the first and last lines to

    Public Function ImportStuff()

    End Function

    You can change "ImportStuff" to whatever has meaning to you. Then in the Function Name argument of the macro put:

    ImportStuff()

    or whatever name you give it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    mchadwick is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Posts
    71
    Thank You, that worked really well.

  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,518
    Happy to help.
    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. auto run Module
    By stu_C in forum Modules
    Replies: 1
    Last Post: 08-01-2011, 06:54 AM
  2. Replies: 4
    Last Post: 05-16-2011, 04:58 PM
  3. Help!! - Corrupted Module
    By rcrobman in forum Modules
    Replies: 3
    Last Post: 04-29-2011, 03:37 PM
  4. need help with import Module
    By marubal21 in forum Modules
    Replies: 1
    Last Post: 07-22-2010, 12:23 AM
  5. Module not found
    By nooby in forum Modules
    Replies: 1
    Last Post: 12-02-2009, 02:20 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