Page 3 of 3 FirstFirst 123
Results 31 to 36 of 36
  1. #31
    Surreall is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Oct 2012
    Posts
    28
    HI,

    My list of attempts is getting bigger, at this stage i dont really care what the code does as long as it runs. Here is what i have tried

    All those with ' are attempts

    Code:
    Sub Mergetwotables()
    
        Dim dbs As DAO.Database
        Dim tdf As DAO.TableDef
        Dim fld As DAO.Field
        Dim strSQL As String
        
    Set dbs = CurrentDb
    
    
    
    'DoCmd.RunSQL "SELECT * FROM AUDUSD60" & _
    '                 "ORDER BY [Date]"
    
      'CurrentDb.OpenRecordset strSQL
    
    'RunSQL "SELECT AUDUSD60."
    'doa.Execute "SELECT AUDUSD60.Date"
    'DoCmd.RunSQL "SELECT Date, Time"
    
    'strSQL = "INSERT INTO AUDUSD60 SELECT * FROM GBPUSD60" & _
    '         "2dbFailOnError"
    
    'CurrentDb.OpenRecordset strSQL
    
    'strSQL = "SELECT Date, Time" & _
    '            "FROM AUDUSD60" & _
    '             "FULL JOIN GBPUSD60" & _
    '             "ON AUDUSD60.Date=GBPUSD60.Date"
    
    'DoCmd.RunSQL strSQL
    
    
    'strSQL = "INSERT INTO table1 SELECT * FROM table2"
    'DoCmd.RunSQL strSQL
    
    'DoCmd.RunSQL strSQL = "INSERT INTO table1 SELECT * FROM table2"
    
    
    
    
    'DoCmd.RunSQL "INSERT INTO AUDUSD60 SELECT * FROM GBPUSD60.Date"
    'dbFailOnError
    
    End Sub


  2. #32
    Surreall is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Oct 2012
    Posts
    28
    I think i am getting my head round it now.....is this the general layout?

    Code:
    Dim strSQL as String
    
    strSQL = "SELECT  etc "
    
    DoCmd.RunSQL strSQL
    ?

  3. #33
    Surreall is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Oct 2012
    Posts
    28
    SOrry for the multiple replies, just updating as i go

    I have the basics working, now i am trying to merge the first to fields together.

    I.e

    Table is laid out like this

    Date, Time, OpenAUDUSD60, CloseAUDUSD60
    12/10/2012, 20:15, 1.45553, 1.66667



    I would like the table to end up like this

    Date, OpenAUDUSD60, CloseAUDUSD60
    12/10/2012 20:15, 1.45553, 1.66667


    And the code i am using which isnt working yet

    Code:
    Sub Mergetwotables()
    
    Dim strSQL As String
    
    strSQL = "INSERT INTO ( Date, Time ) SELECT AUDUSD60.Date & "" "" & AUDUSD60.Time FROM AUDUSD60"
    
    Debug.Print strSQL
    
    DoCmd.RunSQL strSQL
    
    
    End Sub
    Any clues how to fix it?

    Rgds

    Surreall

  4. #34
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,970
    Try:
    strSQL = "INSERT INTO tablename ([Date]) SELECT [Date]" & " " & "[Time] FROM AUDUSD60"

    Instead of DoCmd.RunSQL, I use:
    CurrentDb.Execute strSQL

    RunSQL will trigger warning popups you will have to respond to unless you use:
    DoCmd.SetWarnings = False
    DoCmd.RunSQL strSQL
    DoCmd.SetWarnings = True

    Date and Time are reserved words. Best not to use reserved words as name.
    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. #35
    Surreall is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Oct 2012
    Posts
    28
    I tried your code above and got this error message:

    Syntax error (missing operator) in query expression '[Date] [Time]'.

    Rgds

    Surreall

  6. #36
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,970
    I tested that sql with an Access query and it works. Problem with building the sql in VBA is need the literal & character within the constructed string. I don't have any procedures that call for this construct so I always forget about it and have to look it up. Try:
    strSQL = "INSERT INTO tablename ([Date]) SELECT [Date] " & Chr(38) & " " & Chr(38) & " [Time] FROM AUDUSD60"

    Or create and save Access query object then run that saved query with the VBA code.
    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.

Page 3 of 3 FirstFirst 123
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