Writing code in VBA for SQL Tables

  • I am trying to delete an entire record in a SQL table and it contains a identity column.  I have this code currently and it gives me tis error: You Must Use teh dbSeeChanges option with Open Recordset when accessing a SQL server table that has an IDENTIY column.

    Dim DB As Database

    Dim SQL As String

    SQL = "DELETE * FROM dbo_tblLabor where Counter = " & Right(lbxTimeEntry.SelectedItem.Key, Len(lbxTimeEntry.SelectedItem.Key) - 4)

        Set DB = CurrentDb

        DB.Execute (SQL)

     

    any help would be great

  • "DELETE * FROM" is MS-Access syntax.

    In SQL Server, it is simply "DELETE FROM TableName" (or "DELETE TableName") - I suspect the presence of the '*' implies columns and a resultset being returned, which is causing the error.

  • I tried that and that didn't make any difference, I am wondering if it has anything to do with the db.Execute (SQL) maybe their is more parameters i need to include

  • Have you tried something like:

    Dim oConn As ADODB.Connection

    Dim oRS As ADODB.Recordset

    Dim strConn As String

    DIM strsql As String

    Set oConn = New ADODB.Connection

    strConn = [ado connection string]

    Set strsql = [T-SQL statement]

    oConn.Open (strConn)

    oConn.Execute (strsql)

    Set oRS = oConn.Execute(sSQL)

     

  • Give this a try

     

    db.execute sql, dbseechanges

     

  • check

    HOWTO: Retrieve Values in SQL Server Stored Procedures w/ ADO

     

    in MSDN


    Kindest Regards,

    Vasc

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply