Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. Module ModCob
  2.  
  3. Sub Main()
  4.  
  5.  
  6.  
  7. Const adOpenStatic = 3
  8. Const adLockOptimistic = 3
  9.  
  10.  
  11.  
  12. Dim objConnCli As ADODB.Connection
  13. Dim objConnV As ADODB.Connection
  14. Dim objConnCliUpdate As ADODB.Connection
  15. Dim objCli As ADODB.Recordset
  16. Dim Sqlstr
  17. Dim cCodCli
  18. Dim cNamCli
  19. Dim cObCli
  20. Dim inipos
  21. Dim endpos
  22. Dim nPosCap
  23.  
  24. objConnCli = New ADODB.Connection
  25. objConnV = New ADODB.Connection
  26. objConnCliUpdate = New ADODB.Connection
  27. objCli = New ADODB.Recordset
  28.  
  29.  
  30. objConnCli.Open _
  31. ("Provider =SQLOLEDB; " & "Data Source =test\test,49729;" & "Initial Catalog='testdb';" & "User ID='users';Password='pass';")
  32.  
  33. objConnV.Open _
  34. ("Provider =SQLOLEDB; " & "Data Source =test\test,49729;" & "Initial Catalog='testdb';" & "User ID='users';Password='pass';")
  35.  
  36. objConnCliUpdate.Open _
  37. ("Provider =SQLOLEDB; " & "Data Source =test\test,49729;" & "Initial Catalog='testdb';" & "User ID='users';Password='pass';")
  38.  
  39. Sqlstr = "SELECT * FROM Tclients"
  40. objCli.Open(Sqlstr, objConnCli, adOpenStatic, adLockOptimistic)
  41.  
  42. Do Until objCli.EOF
  43.  
  44. cCodCli = objCli.Fields.Item("Tclients1")
  45. cNamCli = objCli.Fields.Item("Tclients2")
  46. cObCli = objCli.Fields.Item("Tclient5")
  47.  
  48. inipos = InStr(cObCli, "[/Fac:")
  49. endpos = InStr(cObCli, "/]")
  50.  
  51.  
  52. If endpos > 0 Then
  53. nPosCap = endpos + 2
  54. Else
  55. nPosCap = 1
  56. End If
  57.  
  58.  
  59.  
  60.  
  61. Dim cSQLQuery = "SELECT SUM(TVFACV2) FROM TVFACV WHERE TVFACV14='" & cCodCli & "' AND TVFACV4='N' AND TVFACV1<Date()"
  62.  
  63.  
  64. Dim objVen = objConnV.Execute(cSQLQuery)
  65. Dim NDCli
  66. NDCli = objVen(0).Value
  67.  
  68. Dim cExtObCli = Mid(cObCli, nPosCap, 255)
  69.  
  70.  
  71. Dim cNewObCli
  72. Dim cSQLQueryUpdate
  73.  
  74. If NDCli <> 0 Then
  75. cNewObCli = "(/Fac: " & NDCli & " /)" & cExtObCli
  76. Else
  77. cNewObCli = cExtObCli
  78. End If
  79.  
  80.  
  81. cSQLQueryUpdate = "UPDATE Tclients SET Tclients23='" & cNewObCli & "',Tclients22=1,Tclients23=1 where Tclients1='" & cCodCli & "'"
  82.  
  83. If Len(cNewObCli) <= 255 Then
  84.  
  85. Dim objCliUpdate = objConnCliUpdate.Execute(cSQLQueryUpdate)
  86. End If
  87.  
  88. objVen.Close
  89.  
  90. objCli.MoveNext
  91. Loop
  92.  
  93. objConnCli.Close
  94. objConnV.Close
  95. objConnCliUpdate.Close
  96.  
  97.  
  98. End Sub
  99.  
  100. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement