MS SQL Update

moone009

Board Regular
Joined
Jan 26, 2010
Messages
82
Basically whatever column is to the right of my input column I would like to use that value as the value to update in my database.

Before I can even test it to see if it works I keep getting "End if without Block if error" any ideas?

HTML:
Sub SNVlookUP_Server()
    Dim cn As ADODB.Connection
    Dim strSQL As String, i As Integer, ii As Integer
    Dim rst As ADODB.Recordset
    Dim a, b, bb, sA As String, sCol As String, Rng As Range, Rng1 As Range, InputBox As String
    
'**********************************************************************************************'
'sCol is where the user will enter the column of the look up value
'**********************************************************************************************'
    ''InputBox = Application.InputBox("Insert DB Connections:")
    sCol = Application.InputBox("Please input the column of the look up value:")
    If VBA.Len(sCol) = 0 Then
        MsgBox "No column is selected!"
    Else
        Set Rng = Range(Cells(1, sCol), Cells(65536, sCol).End(xlUp))
        Set Rng1 = Range(Cells(2, 2), Cells(65536, 2).End(xlUp))
        a = Application.WorksheetFunction.Transpose(Rng.Value)
        bb = Application.WorksheetFunction.Transpose(Rng1.Value)
        b = a
        Set cn = New ADODB.Connection
        cn.Open msConnStringDB
        For i = LBound(a) To UBound(a)
        For ii = LBound(bb) To UBound(bb)
'**********************************************************************************************'
'To change the look up value change it.viItemName

'To change the value that the look up value is referencing change "max(th.TransDate) as MaxDate"
'**********************************************************************************************'

                    strSQL = "Update lalocation " & _
                    "Set propertydatamap = '" & VBA.Trim$(bb(ii)) & "'" & _
                    "WHERE ServiceNumber ='" & VBA.Trim$(a(i)) & "'"
                    Set rst = cn.Execute(strSQL)
                
Next
        Rng.Offset(0, 1).Value = Application.WorksheetFunction.Transpose(b)
        cn.Close
        Set cn = Nothing
End If

End Sub
 
Last edited:

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
You have two Fors but only one Next. Is that single Next intended to terminate both For loops?

If so, change it to Next ii, i.
 
Last edited:
Upvote 0
You need to add a next, and you should probably include the loop control variables not just Next on it's own - it get's lonely and doesn't know who to talk to.:)
Code:
        For i = LBound(a) To UBound(a)
            For ii = LBound(bb) To UBound(bb)
                '**********************************************************************************************'
                'To change the look up value change it.viItemName
                'To change the value that the look up value is referencing change "max(th.TransDate) as MaxDate"
                '**********************************************************************************************'
                strSQL = "Update lalocation " & _
                         "Set propertydatamap = '" & VBA.Trim$(bb(ii)) & "'" & _
                         "WHERE ServiceNumber ='" & VBA.Trim$(a(i)) & "'"
                Set rst = cn.Execute(strSQL)
            Next ii
        Next i
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,777
Members
452,942
Latest member
VijayNewtoExcel

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top