Results 1 to 21 of 21

SQL Problem in UPDATE

Threaded View

  1. #1
    Registered User
    Join Date
    03-12-2009
    Location
    Loughborough, England
    MS-Off Ver
    Excel 2007
    Posts
    22

    SQL Problem in UPDATE

    Hi
    Having mastered adding new records to an Access table via ADO, I now need to amend and delete ( Seperately ).

    Working on the amend code in my module, I have got the connection working fine and the Select statement is good also I believe, but I keep getting syntax errors on the UPDATE string shown as STRSQL Can someone please point me in the right direction ?

    Any hints on adapting for record deletion would be appreciated also ?

    Kind Regards

    Ian
    Sub Modify_Records()
    Dim cnt As ADODB.Connection
    Dim rst As ADODB.Recordset
    Dim stsql As String
    Dim stCon As String
    Dim wbBook As Workbook
    Dim wsSheet As Worksheet
    Dim rnData As Long
    Dim vaData As Variant
    Dim i As Long
    Dim j As Long
    Dim strsql As String
    Dim ref As String
    Dim db As Database
    
        Set wbBook = ThisWorkbook
        Set wsSheet = wbBook.Worksheets("Log")
        rnData = wsSheet.Cells(Rows.Count, 1).End(xlUp).Row
        
        vaData = rnData
       
        stCon = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source= G:\EBKN_Public\Booking Board\Data Table.mdb"
         
        
        Set cnt = New ADODB.Connection
        Set rst = New ADODB.Recordset
         
        cnt.Open stCon
         
        For i = 3 To vaData
        ref = wsSheet.Cells(i, 1).Value
        stsql = "SELECT * FROM Log WHERE Booking_Ref='" & ref & "'"    
        With rst
       .Open strsql, cnt, 3, 3, adCmdTable
                
       If .EOF And .BOF Then
       MsgBox "No Data"
       Else
       strsql = "UPDATE Log" & "SET Date = " & wsSheet.Cells(i, 2) & "," & "Time = '" & wsSheet.Cells(i, 3) & "'," & "Bay ='" & wsSheet.Cells(i, 4) & "' " & "WHERE Booking_Ref ='" & wsSheet.Cells(i, 1) & "'"
       End If
       .Close
       End With
       stsql = Empty
       strsql = Empty
       Next
       
       cnt.Close
       'Release objects from memory.
        Set rst = Nothing
        Set cnt = Nothing
    End Sub
    Last edited by romperstomper; 07-25-2011 at 07:06 AM.

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