Guest User

Untitled

a guest
Nov 23rd, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. 'Option Explicit
  2.  
  3. Sub TESTQT()
  4.  
  5. 'Dim qt As QueryTable
  6. Dim Datum As Long
  7. Dim SQL As String
  8. Dim conn As String
  9. 'ndatum = Application.InputBox(prompt:="Vložte datum vystavení dokladu DO:", Default:=Format(Date, "d.m.yyyy"), Type:=2)
  10. ndatum = ActiveCell(1, -1)
  11. Datum = ndatum
  12. SQL = "SELECT sum(A.LocalAmount) "
  13. SQL = SQL + " -sum((SELECT LocalAmount FROM PaymentAmountsForRCreditNote (A.ID, " & Datum & ")))"
  14. SQL = SQL + " +sum((SELECT LocalPAmount FROM PaymentAmountsForRCreditNote (A.ID, " & Datum & ")))"
  15. SQL = SQL + " -sum((SELECT COALESCE(SUM(LocalPAmount),0) FROM PaymentsForDocument ('04', A.ID, " & Datum & ")))"
  16. SQL = SQL + " FROM ReceivedInvoices A"
  17. conn = "ODBC;DSN=ABRA"
  18. Set qtable = ActiveSheet.QueryTables.Add(Connection:=conn, Destination:=Range(ActiveCell.Address), SQL:=SQL)
  19. qtable.FieldNames = False
  20. 'qtable.SaveData = False
  21. 'qtable.MaintainConnection = False
  22. qtable.Refresh BackgroundQuery:=False
  23. 'qtable.Refreshing
  24. ' .Name = "Contact List"
  25. ' .FieldNames = True
  26. ' .RowNumbers = False
  27. ' .FillAdjacentFormulas = False
  28. ' .PreserveFormatting = True
  29. ' .RefreshOnFileOpen = False
  30. ' .BackgroundQuery = True
  31. ' .RefreshStyle = xlInsertDeleteCells
  32. ' .SavePassword = True
  33. ' .SaveData = True
  34. ' .AdjustColumnWidth = True
  35. ' .RefreshPeriod = 0
  36. ' .PreserveColumnInfo = True
  37. ' .Refresh BackgroundQuery:=False
  38.  
  39. End Sub
  40.  
  41. Sub getFA()
  42.  
  43. Dim wrk As DAO.Workspace
  44. Dim cnn As DAO.Connection
  45. Dim rs As DAO.Recordset
  46. Dim sConn As String
  47. Dim xlSheet As Worksheet
  48. Dim iFieldCount As Integer
  49. Dim i As Integer
  50.  
  51. Set xlSheet = Sheets("Sheet1")
  52. xlSheet.Activate
  53. Range("A1").Activate
  54. Selection.CurrentRegion.Select
  55. Selection.ClearContents
  56. Range("A1").Select
  57.  
  58. sConn = "ODBC;DSN=ABRA"
  59.  
  60. Set wrk = CreateWorkspace("", "", "", dbUseODBC)
  61. Set cnn = wrk.OpenConnection("", , , sConn)
  62. Set rs = cnn.OpenRecordset("Select * FROM Accounts", dbOpenDynamic)
  63.  
  64.  
  65.  
  66. End Sub
  67.  
  68. Sub getFA2()
  69.  
  70.  
  71. Set cnnConnect = "ODBC;DSN=ABRA"
  72.  
  73. Set rstRecordset = New ADODB.Recordset
  74. strSQL = "SELECT * from Accounts"
  75.  
  76. rstRecordset.Open Source:=strSQL, _
  77. ActiveConnection:=cnnConnect, _
  78. CursorType:=adOpenDynamic, _
  79. LockType:=adLockReadOnly, _
  80. Options:=adCmdText
  81.  
  82. varMaxYear = rstRecordset.Fields("MaxOfPYEAR").Value
  83. rstRecordset.Close
  84. End Sub
Add Comment
Please, Sign In to add comment