Results 1 to 8 of 8
  1. #1
    dr91075 is offline Novice
    Windows Vista Access 2007
    Join Date
    Mar 2013
    Posts
    22

    Load objects into newly created database from text files


    Hello all,

    I would like to load objects into a newly created database from text files. Is this possible?

    I am creating the database using the following:
    Code:
    Function CreateNewDatabase(strPath As String, strName As String) As Database
    Dim WS As Workspace, db As Database, strFullName As String
        strFullName = strPath & "/" & strName
        Set WS = DBEngine.Workspaces(0)
        If Dir(strFullName) <> "" Then Kill strFullName
        Set db = WS.CreateDatabase(strFullName, dbLangGeneral)
    End Function
    
    Sub Test()
    Dim db As Database
    Set db = CreateNewDatabase(CurrentProject.Path, "TestMe.accdb")
    End Sub
    I can import objects into the "current" database using TransferText, but I can't seem to accomplish this externally. Any ideas or help would be greatly appreciated.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Code to read/write/create textfile http://www.databasedev.co.uk/text_files.html

    Might be able to read each line of text file, parse the data, and save to table of external database. I am not sure if would be by opening an editable recordset of the external table and adding records or by sql INSERT action. I have used both methods for moving data between 2 dbs (the one with code and one external), but never between two external to the coded db.
    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
    dr91075 is offline Novice
    Windows Vista Access 2007
    Join Date
    Mar 2013
    Posts
    22
    Thanks, June. I appreciate the reply. However, the newly created database would not have any tables. That's the part I'm stuck on. I guess a more accurate question would be how do I move focus from the current database to the created one so that it becomes the current database?

    I'm sorry if I'm not explaining well. I've programmed with Excel for a long time, but I'm new to Access.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    I made assumption you would have code to create tables after creating the db.

    AFAIK, can't 'move focus' to the created db.

    Can open the new db file and manually go to it (mouse click).
    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.

  5. #5
    dr91075 is offline Novice
    Windows Vista Access 2007
    Join Date
    Mar 2013
    Posts
    22
    Thanks again, June. The tables are to be created from the text files. They don't reside in any database. I could import them into the current database and export them to the new one, but I'm concerned about the bloating as this will be done periodically by users. Perhaps it's the only option, though.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Why would need new tables and not import data to existing tables?

    I have code in one db that periodically creates a db, extracts data into new db, zips the db, emails the db, deletes the new db. The extract code is like:
    CurrentDb.Execute "SELECT * INTO tablename IN 'C:\filename.accdb' FROM queryname;"

    Then in another db I have code to import data from another db:
    DoCmd.RunSQL "INSERT INTO tablename(FAAID) SELECT FAAID FROM [" & strSourcePath & "].tablename;"

    Seems that code in db1 should be able to grab data from external source (db2 or text file) and insert into db3. In the case of text file, since TransferText won't work, think have to first create the table then use INSERT action of parsed data from text file.
    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.

  7. #7
    dr91075 is offline Novice
    Windows Vista Access 2007
    Join Date
    Mar 2013
    Posts
    22
    Thanks June. I'll give this some thought.

  8. #8
    dr91075 is offline Novice
    Windows Vista Access 2007
    Join Date
    Mar 2013
    Posts
    22
    Just to update... I was able to work this out by storing the code to import the textfiles in the current database, exporting the module to the newly created database, and running that procedure...

    Code:
    Sub CreateNew()
        Dim acApp As Access.Application
        
        CreateNewDatabase CurrentProject.Path, "NewTester.accdb"
        DoCmd.TransferDatabase acExport, "Microsoft Access", CurrentProject.Path & "/NewTester.accdb", acModule, "Module3", "Module3"
        
        Set acApp = CreateObject("Access.Application")
        acApp.OpenCurrentDatabase CurrentProject.Path & "/NewTester.accdb"
        acApp.Run "ImportForms"
        Set acApp = Nothing
    End Sub

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

Similar Threads

  1. Clear text box on form load
    By RoyLittle0 in forum Access
    Replies: 3
    Last Post: 03-05-2013, 05:40 AM
  2. Replies: 5
    Last Post: 12-18-2012, 02:37 PM
  3. Change the text box color on form load
    By mikec in forum Programming
    Replies: 2
    Last Post: 03-01-2010, 11:47 PM
  4. New Field Name on Newly created query
    By inan25 in forum Queries
    Replies: 3
    Last Post: 05-13-2009, 09:05 PM
  5. Best Way to Return a Newly Created Index?
    By Jerimiah33 in forum Programming
    Replies: 5
    Last Post: 09-06-2006, 12:22 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