Results 1 to 5 of 5

Thread: import csv ind create new table

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,935

    import csv ind create new table

    with ado please...
    I use the tipical ado conn.(the access database source is in c:\my_dir1 and is named test1.mdb)

    In c:\my_dir\ have a file named test.csv (comma delimited).

    The csv file contain the header name of column.

    The column DATE contain a dates in usa format (mm/dd/yyyy).
    The column AGENCY contain a values with 3 or 4 characters.


    Now, via ADO or with other..., i need to create with the csv file a new table in the mdb test1.mdb named MYTABLE_&DATA (DATA is a datae variable)
    but during the import of csv in table change the format of column DATE in dd/mm/yyyy and change the format of column AGENCY in #0000

    tKS. i hope understand me.

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: import csv ind create new table

    Code:
    me.caption=format(Date,"dd/mm/yyyy")
    Some thing like this...???

    Give us a detailed view of your problem....!!!

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: import csv ind create new table

    If you want to use the Access Object Model...

    Code:
    Option Explicit
    'Add a reference to Microsoft Access xx.0 Object Library
    Private moApp As Access.Application
    
    Private Sub Command1_Click()
        On Error GoTo My_Error
    
        Set moApp = CreateObject("Access.Application")
        moApp.DoCmd.SetWarnings False
        moApp.OpenCurrentDatabase "C:\RobDog888.mdb"
        moApp.DoCmd.TransferText acImportDelim, , "Table1", "C:\Test.csv", True
        'Optionally show the table if you want confirmation it imported
        'moApp.Visible = True
        'moApp.DoCmd.OpenTable "Table1", acViewNormal, acEdit
        moApp.DoCmd.SetWarnings True
        Exit Sub
    My_Error:
        MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbExclamation
    End Sub
    
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
        On Error GoTo My_Error
        
        moApp.CurrentDb.Close
        moApp.Quit acQuitPrompt
    MyError:
        Set moApp = Nothing
    End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,935

    Re: import csv ind create new table

    Quote Originally Posted by RobDog888 View Post
    If you want to use the Access Object Model...

    Code:
    Option Explicit
    'Add a reference to Microsoft Access xx.0 Object Library
    Private moApp As Access.Application
    
    Private Sub Command1_Click()
        On Error GoTo My_Error
    
        Set moApp = CreateObject("Access.Application")
        moApp.DoCmd.SetWarnings False
        moApp.OpenCurrentDatabase "C:\RobDog888.mdb"
        moApp.DoCmd.TransferText acImportDelim, , "Table1", "C:\Test.csv", True
        'Optionally show the table if you want confirmation it imported
        'moApp.Visible = True
        'moApp.DoCmd.OpenTable "Table1", acViewNormal, acEdit
        moApp.DoCmd.SetWarnings True
        Exit Sub
    My_Error:
        MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbExclamation
    End Sub
    
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
        On Error GoTo My_Error
        
        moApp.CurrentDb.Close
        moApp.Quit acQuitPrompt
    MyError:
        Set moApp = Nothing
    End Sub

    Hi friend.. and sorry for delay.
    No. i want to use vb6 or vba for excel

  5. #5
    New Member
    Join Date
    Oct 2009
    Location
    Roma Italy
    Posts
    9

    Re: import csv ind create new table

    Hello
    to create the table Tbl_MYTABLE with VB6 you can use the following code:
    Code:
    'Crea la Tabella:
    Private Sub Command1_Click()
    
        Dim Conn As New ADODB.Connection
        Dim OggTbl As New ADODB.Command
      'Esegue la connessione con il DataBase:
            Conn.ConnectionString = DBCon
            Conn.CommandTimeout = 15
            Conn.Open
    
    'Crea la tabella Tbl_MYTABLE:
        OggTbl.ActiveConnection = Conn
        OggTbl.CommandType = adCmdText
        OggTbl.CommandText = "create table Tbl_MYTABLE(IDCliente autoincrement primary Key, Nome Text(50) Not Null, Cognome Text(50) Not Null, Indirizzo Text(100))"
        OggTbl.Execute
    
     'Chiude e cancella la connessione:
                Conn.Close
                Set Conn = Nothing
    End Sub
    For the rest I did not quite understand...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width