Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 36
  1. #16
    Surreall is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Oct 2012
    Posts
    28
    I really appreciate your help thankyou, how do you resave the file? As i am having trouble with that



    Rgds

    Surreall

  2. #17
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Resave what 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.

  3. #18
    Surreall is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Oct 2012
    Posts
    28
    Hi June7,

    I have found somewhere else to get my csv files from and now there is no problem with it. They import wonderfully. I have a few questions about how to go about organising them if that is okay?

    Regards

    Surreall

  4. #19
    Surreall is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Oct 2012
    Posts
    28
    Hi again,

    I have written the following code, which imports two csv files and renames the fields as follows
    Field 1: Date
    Field 2: Time

    1stTable currently set out like this........(field names in order)......Date, Time, Open AUDUSD60, High AUDUSD60, Low AUDUSD60, Close AUDUSD60, Sales AUDUSD60
    2ndTable currently set out like this..........................................Date , Time, Open GBPUSD60, High GBPUSD60, Low GBPUSD60, Close GBPUSD60, Sales GBPUSD60

    What i would like to do is write a VBA code that merges these two comparing date & time and add the other columns to that table eg

    New merged table would look like Date, Time, Open AUDUSD60, High AUDUSD60, Low AUDUSD60, Close AUDUSD60, Sales AUDUSD60, Open GBPUSD60, High GBPUSD60, Low GBPUSD60, Close GBPUSD60, Sales GBPUSD60

    So new table would have 12 columns and where all date and time matched (has to be both)

    So if i look at the new table i can go to a particular time and see the sales for both audusd and gbpusd.

    The only problem is that gbpusd has about a third of the number of rows as the first table. So there will be blanks next to some of the date and times for the last 5 columns.

    Does that make sense?

    Rgds

    Surreall

    PS ultimately i will have a lot more csv files so will look to do this with all of them

    Code:
    Sub Import_multiple_csv_files()
    
    
    Dim My_Array
    
    My_Array = Array("AUDUSD60", "GBPUSD60")
    
    For i = LBound(My_Array) To UBound(My_Array)
    
        Currentcsvfile = My_Array(i)
    
        DoCmd.TransferText acImport, , Currentcsvfile, "C:\" & Currentcsvfile & ".csv", False
    
        Dim dbs As DAO.Database
        Dim tdf As DAO.TableDef
        Dim fld As DAO.Field
    
        Set dbs = CurrentDb
        Set tdf = dbs.TableDefs(Currentcsvfile)
    
        Set fld = tdf.Fields("F1")
        fld.Name = "Date"
    
        Set fld = tdf.Fields("F2")
        fld.Name = "Time"
    
        Set fld = tdf.Fields("F3")
        fld.Name = "Open " & Currentcsvfile & ""
    
        Set fld = tdf.Fields("F4")
        fld.Name = "High " & Currentcsvfile & ""
    
        Set fld = tdf.Fields("F5")
        fld.Name = "Low " & Currentcsvfile & ""
    
        Set fld = tdf.Fields("F6")
        fld.Name = "Close " & Currentcsvfile & ""
    
        Set fld = tdf.Fields("F7")
        fld.Name = "Sales " & Currentcsvfile & ""
    
        dbs.Close
        Set dbs = Nothing
        Set fld = Nothing
        Set tdf = Nothing
    
    Next i
    
    MsgBox "Changed"
    'Call changefieldnames
    
    
    End Sub

  5. #20
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Seems to make sense. What exactly do you need? Does code work?

    BTW, Date and Time are reserved words in Access/VBA. Should not use reserved words as names.
    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.

  6. #21
    Surreall is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Oct 2012
    Posts
    28
    Quote Originally Posted by June7 View Post
    Seems to make sense. What exactly do you need? Does code work? BTW, Date and Time are reserved words in Access/VBA. Should not use reserved words as names.
    Yep code works great. It loads two tables What i am looking to do i said above, merge the two tables. With Date and time as the reference. Please see above Rgds Surreall

  7. #22
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Merge? Is the combined Date/Time value unique to each record in each table but is common to both tables? If so, build a query that joins the two tables on the Date/Time fields. Use the query as basis for reports or to make another table.

    That or write code to import both csv files to same table.
    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.

  8. #23
    Surreall is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Oct 2012
    Posts
    28
    Quote Originally Posted by June7 View Post
    Merge? Is the combined Date/Time value unique to each record in each table but is common to both tables? If so, build a query that joins the two tables on the Date/Time fields. Use the query as basis for reports or to make another table. That or write code to import both csv files to same table.
    Date and time is the same for both tables, well the second table as some missing times How do import two csv files into the same table? Or more to the point how do i import lost of csv files into the same table? Rgds Surreall

  9. #24
    Surreall is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Oct 2012
    Posts
    28
    With vba how do import two csv files into the same table? Yes date and time is the same for both tables. Although the second table has some dates missing Rgds Surreall

  10. #25
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I don't have need for importing csv files so I could be wrong on methodology, but I don't think could use TransferText to import additional fields to an existing file. TransferText either creates new table or adds records (in the corresponding existing fields) of existing table.

    Other method to import csv file would open recordset of the existing table and enter data to specified fields of specific record by looping through the csv file opened as an object in VBA procedure. Code would have to parse each line of the text file, probably to an array using Split function. Then feed each value to recordset. Gets rather tricky. For a start, review
    http://forums.aspfree.com/microsoft-...vba-30159.html
    http://www.applecore99.com/gen/gen029.asp
    http://msdn.microsoft.com/en-us/libr...ffice.10).aspx
    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.

  11. #26
    Surreall is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Oct 2012
    Posts
    28
    How about using VBA to import the two seperate files have i have done. And then use vba to merge the two tables?

  12. #27
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Yes, can do.

    Do you need code to create the fields - which is what you show in the sample you posted.

    Use VBA to execute SQL actions - UPDATE, MAKE TABLE, ALTER TABLE, INSERT - as well as the TableDefs collection for some table edits.
    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.

  13. #28
    Surreall is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Oct 2012
    Posts
    28
    Help with the code would be great, using my code above. Or a link to get me started? Rgds Surreall

  14. #29
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Lots of resources. I already posted 3 links.

    Here is one about SQL http://w3schools.com/sql/default.asp
    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.

  15. #30
    Surreall is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Oct 2012
    Posts
    28
    I am having a real problem with syntax for sql for example:

    Code:
    Sub Mergetwotables()
    
        Dim dbs As DAO.Database
        Dim tdf As DAO.TableDef
        Dim fld As DAO.Field
    
    Set dbs = CurrentDb
    
    'RunSQL "SELECT AUDUSD60."
    'doa.Execute "SELECT AUDUSD60.Date"
    'DoCmd.RunSQL "SELECT Date, Time"
    'DoCmd "INSERT INTO AUDUSD60 SELECT * FROM GBPUSD60"
    dbFailOnError
    
    End Sub
    None of these work, i know i am probably doing something stupid, i keep getting debugs on all lines but i don't know the correct syntax for calling sql commands. The two tables are called AUDUSD60 & GBPUSD60

    I havent done code for merging yet, as i cannot get the syntax to work with simple statements yet

    Regards

    Surreall

Page 2 of 3 FirstFirst 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Edit Results
    By ShadeRF in forum Reports
    Replies: 1
    Last Post: 11-18-2011, 02:03 PM
  2. Edit user name
    By accessnewb in forum Programming
    Replies: 25
    Last Post: 08-04-2011, 02:52 PM
  3. Cannot edit tables at random
    By neo651 in forum Access
    Replies: 3
    Last Post: 06-02-2011, 11:45 AM
  4. edit combobox
    By nako in forum Database Design
    Replies: 1
    Last Post: 06-23-2010, 05:56 AM
  5. Replies: 3
    Last Post: 08-06-2009, 11:49 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