Results 1 to 6 of 6
  1. #1
    mike02 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    245

    Importing CSV


    hey,

    I have 9 buttons on my form. all have this on click command:

    Code:
    Function Import()
    On Error GoTo Import_Err
      
    Dim strFilter As String
    Dim strInputFileName As String
      
      strFilter = ahtAddFilterItem(strFilter, "CSV Files (*.CSV)", "*.CSV")
      strInputFileName = ahtCommonFileOpenSave( _
                    Filter:=strFilter, OpenFile:=True, _
                    DialogTitle:="Please select an input file...", _
                    Flags:=ahtOFN_HIDEREADONLY)
     'Actual import
      If Len(strInputFileName) > 0 Then
        DoCmd.TransferText acImportDelim, "Import Specification", "tbl_Import", strInputFileName, False, ""
        
      End If
      
    Import_Exit:
      Exit Function
      
    Import_Err:
      MsgBox Error$
      Resume Import_Exit
      
    End Function
    When this code runs i want it to import to append it to the table. each button corresponds with its table. if someone could show me how to write this, that would be fantastic! thanks

  2. #2
    help_me_with_access is offline help_me_with_excel
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    262
    what is this doing for you now?

    Code:
    DoCmd.TransferText acImportDelim, "Import Specification", "tbl_Import", strInputFileName, False, ""
    doesn't that work? if you want Access to teach you how, try creating a macro with this action and add all the arguments as necessary. then click the "convert to VBA" button on the ribbon for the macro.

  3. #3
    mike02 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    245
    it runs error, "The text file specification 'Import Specification' Does not exist. You cannot import, export, or link using the specification"

    is there a way to run the append to table....tblname here..

    Ie. Me.(Name of button?)=tblename, Append?

  4. #4
    help_me_with_access is offline help_me_with_excel
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    262
    Quote Originally Posted by mike02 View Post
    is there a way to run the append to table....tblname here..

    Quote Originally Posted by mike02 View Post
    Ie. Me.(Name of button?)=tblename, Append?
    no idea what this is. no, that's not it.

    Quote Originally Posted by mike02 View Post
    it runs error, "The text file specification 'Import Specification' Does not exist. You cannot import, export, or link using the specification"
    Do you actually HAVE an import spec saved in your file? if you don't, the message is valid. but there are unknown problems (to me) surrounding the concept of using save import and export specs using vb code. you should avoid it. I believe there is a bug in the program involved with import and exports specs and vb coding.

    an immediate workaround though, would be to always import into a temp table, then run a simple append query from vb coding by spec'ing input criteria from where-ever...your form perhaps? for a double-transaction like that though, I would certainly use a DOEVENTS() between the 2 transactions.

    don't forget too, your last post (since it was so long) might be a good reference even now that you've progressed a bit:

    https://www.accessforums.net/forms/i...elp-26991.html

  5. #5
    mike02 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    245
    Quote Originally Posted by help_me_with_access View Post
    no idea what this is. no, that's not it.
    I know thats not it. I was just seeing if there was something with that idea would work. What would i put for my specifications? I dont know what you mean by the file having a speccification for the import file:S sorry, still teaching my self VBA. thanks,

  6. #6
    help_me_with_access is offline help_me_with_excel
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    262
    on the ribbon => "saved imports/exports". this is the feature that stores the schema which tells access what, where, how to import/export.

    so to expand on what i mentioned earlier...save an import by creating one with the wizard and saving it under a name. import the data into a common-named table. so then if you have a saved import spec like that, you can do what you need (as a process) with 2 lines of code:

    Code:
    docmd.setwarnings = 0
    DoCmd.TransferText (args)
      doevents
    docmd.runsql "APPEND QUERY here, where you can reference object controls in the SQL command"
    docmd.setwarnings = -1
    that's a starting point. follow?

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

Similar Threads

  1. Importing a PDF
    By JHighley in forum Access
    Replies: 6
    Last Post: 07-24-2012, 08:39 AM
  2. Need help importing to SQL
    By winterh in forum SQL Server
    Replies: 14
    Last Post: 03-28-2012, 12:36 PM
  3. Need Help about importing from Excel
    By Nicc V in forum Access
    Replies: 6
    Last Post: 12-12-2011, 03:11 PM
  4. Help with Importing
    By Souperbc in forum Programming
    Replies: 2
    Last Post: 04-13-2011, 12:45 PM
  5. Need help in importing table
    By sdondeti in forum Access
    Replies: 6
    Last Post: 11-16-2009, 09:38 AM

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