Updated Data Shows In Excel After Some Inconsistant

kashif.special2005

Active Member
Joined
Oct 26, 2009
Messages
443
Hi,

I am updating data in a table in sql server from excel, and after updating the data I am fetching the updated data in excel, and when I fetch the updated data sometime updated record show and some time after 2 or 3 click on refresh button then the updated data shows, I don't know what I am doing wrong.

Please help me to resolve the issue.

Code:
Public Sub UpdateRequest()
Dim ID As Variant, cn As Variant, rs As Variant, RequestID As Variant
Dim StartRow As Long, EndRow As Long, i As Long, PeopleID As Long, Assoc As Long, SysStatus As Long, PortfolioID As Long
Dim strSQL As String, Status As String
Dim dateTime As Date
On Error Resume Next
With Application
    .EnableEvents = False
    .ScreenUpdating = False
    .DisplayAlerts = False
End With
Set Data = Worksheets("Data")
With Data
    ID = .Range(.Cells(StartRow, 1), .Cells(EndRow, EndCol)).Value2
    .Cells.ClearContents
End With
For i = 1 To UBound(ID)
    If ID(i, 1) <> "" And ID(1, 1) <> "RequestID" Then
        RequestID = ID(i, 1)
        PortfolioID = ID(i, 3)
        Status = ID(i, 20)
        If Status = "Entry" Then
            SysStatus = 1
        ElseIf Status = "EntryTransaction" Then
            SysStatus = 2
        ElseIf Status = "QC" Then
            SysStatus = 3
        ElseIf Status = "Complete" Then
            SysStatus = 4
        Else: Status = "Entry"
            SysStatus = 1
        End If
        
        '#1 Send Log
        Set cn = New ADODB.Connection
        Set rs = New ADODB.Recordset
        
        cn.Provider = "sqloledb"
        cn.Open = "Server=ServerName;Initial Catalog=DataBaseName;Integrated Security=SSPI;"
        
        Set rs.ActiveConnection = cn
            strSQL = "SELECT * FROM TableName w WHERE w.RequestID = ('" & RequestID & "')"
            rs.Open strSQL, cn, 1, 3
            
            With rs
                If rs.RecordCount = 0 Then
                    .AddNew
                    !RequestID = RequestID
                    Assoc = StatusCheck(RequestID, 0, SysStatus, PortfolioID)
                Else
                    Assoc = StatusCheck(RequestID, 1, SysStatus, PortfolioID)
                End If
                
                !SysStatus = SysStatus
                !DataProcessingAssoc = Assoc
                !DataProcessingNotes = ID(i, 21)
                !SysAction = 6
                !SysTime = dateTime
                !ApplicationID = 4
                !ApplicationVersion = 1.1
                .Update
            End With
        'Close connections
        rs.Close
        cn.Close
    End If
Next i
'Here in this module fetching the data from sql server and pasting the data in excel
Call Request_Manager
With Application
    .EnableEvents = True
    .ScreenUpdating = True
    .DisplayAlerts = True
End With
On Error GoTo 0
End Sub

Thanks
Kashif
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Forum statistics

Threads
1,214,976
Messages
6,122,541
Members
449,089
Latest member
davidcom

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