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.
Thanks
Kashif
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