+ Reply to Thread
Results 1 to 7 of 7

rum time error 3065

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-05-2011
    Location
    behind you!
    MS-Off Ver
    Excel 2010
    Posts
    116

    rum time error 3065

    Hi,

    I wrote this simple code:

    Sub DBDELETE_SQL(Path As String, Table As String, SQL As String)
    
        Dim DB As Database
        Dim RS As Recordset
        
        Set DB = OpenDatabase(Path)
        Set RS = DB.OpenRecordset(Table, dbOpenTable)
        
        DB.Execute SQL
        
    
        RS.Close
        Set RS = Nothing
        DB.Close
        Set DB = Nothing
    
    End Sub
    I call the sub in this manner:

    ...
    SQL = "Select * from History where ID=3 and Date=" & Chr(34) & "2013-03-10 - 2013-03-16" & Chr(34)
    Call DBDELETE_SQL("C:\GoogleTrends3.mdb", "History", SQL)
    ...
    I get this error: Run-time-error '3065': Application-defined or object-defined error

    What is wrong??

    Thank you, for any help!
    Lloyd

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: rum time error 3065

    Lloyd

    Try putting Date in square brackets in the SQL.

    By the way, is Date a date/time field or a text field?
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    04-05-2011
    Location
    behind you!
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: rum time error 3065

    Hi Norie,

    thank you for your fast reply!

    "Select * from History where ID=3 and [Date]="2013-03-10 - 2013-03-16""
    Causes the same error!

    Date is a text field!

    I found out Date is a reserved word in SQL, so I renamed the attribute to Datum. But thsi also causes the same error!

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: rum time error 3065

    Lloyd

    The reason I suggested the square brackets was because Date is reserved.

    Instead of trying to use double quotes try single quotes.
    "SELECT * FROM History WHERE ID=3 AND [Datum]='2013-03-10 - 2013-03-16'"
    By the way, .Execute is normally used with action queries, eg DELETE, UPDATE etc not SELECT queriesl like you have.

  5. #5
    Forum Contributor
    Join Date
    04-05-2011
    Location
    behind you!
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: rum time error 3065

    Hmm, this does not help, too.

  6. #6
    Forum Contributor
    Join Date
    04-05-2011
    Location
    behind you!
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: rum time error 3065

    I wrote a new Sub:

    Sub DeleteRecordsUsingSQL(Path As String, SQL As String)
    
        Dim DB As DAO.Database
        Set DB = OpenDatabase(Path)
        DB.Execute SQL, dbFailOnError
        Set DB = Nothing
    
    End Sub
    "Delete * from History where ID=3 and [Datum]="2013-03-10 - 2013-03-16""
    It works.

    Lloyd

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: rum time error 3065

    Lloyd

    So the problem was the SELECT query as I kind of mentioned in my last post.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1