Advertisement
Guest User

joesesal odbc kunden 02

a guest
Jul 10th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ' Option Explicit
  2.  
  3.  
  4. '''''   This is lame.  Be ashamed of yourself
  5. Sub test()
  6.  
  7.    
  8.     ' On Error Resume Next
  9.  
  10.  
  11. Const adOpenStatic = 3
  12. Const adLockOptimistic = 3
  13. Const adCmdText = &H1
  14.  
  15. Set objConnection = CreateObject("ADODB.Connection")
  16. Set objRecordset = CreateObject("ADODB.Recordset")
  17.  
  18. ' Provider=Microsoft.Jet.OLEDB.4.0
  19. ' Provider=Microsoft.ACE.OLEDB.12.0
  20. objConnection.Open "Provider=Microsoft.ACE.OLEDB.12.0;" & _
  21.     "Data Source=\\POEL5-DATEN\Altona-Büro-Dateien\11 Büroteam\Joe Koenig\Excel Übungen\Joe  auftragsreport.xlsm;" & _
  22.         "Extended Properties=""Excel 8.0;HDR=Yes;"";"
  23.  
  24. Dim sqlString As String
  25.  
  26. ' sqlString = "SELECT  * from [Auftragseingang$] WHERE Datum IS NOT NULL ORDER BY Datum ASC "
  27.  
  28. ' sqlString = "SELECT  Kunde, count(Kunde) from [Auftragseingang$] group BY Kunde"
  29.  
  30. sqlString = "SELECT  distinct(Kundenname) from [Kunden$] WHERE Kundenname is not null AND trim(Kundenname) <> '' "
  31. objRecordset.Open sqlString & " ", objConnection, adOpenStatic, adLockOptimistic, adCmdText
  32.  
  33. Dim i As Integer
  34. i = 0
  35. Dim j As Integer
  36. j = 0
  37.  
  38. Dim Kunden() As String
  39. ReDim Kunden(0)
  40.  
  41. ' Debug.Print UBound(Kunden)
  42.  
  43. Do While Not objRecordset.EOF
  44.     Kunden(UBound(Kunden)) = objRecordset.Fields(0)
  45.     ReDim Preserve Kunden(UBound(Kunden) + 1)
  46.     ' Debug.Print "Record: " & objRecordset.Fields(0)
  47.    objRecordset.MoveNext
  48. Loop
  49. objRecordset.Close
  50.  
  51.  
  52. Dim Mitarbeiter() As String
  53. ReDim Mitarbeiter(0)
  54.  
  55. sqlString = "SELECT  distinct(Mitarbeiter) from [Mitarbeiter$] WHERE Mitarbeiter is not null AND trim(Mitarbeiter) <> '' "
  56. objRecordset.Open sqlString & " ", objConnection, adOpenStatic, adLockOptimistic, adCmdText
  57.  
  58. Do While Not objRecordset.EOF
  59.     Mitarbeiter(UBound(Mitarbeiter)) = objRecordset.Fields(0)
  60.     ReDim Preserve Mitarbeiter(UBound(Mitarbeiter) + 1)
  61.     ' Debug.Print "Record: " & objRecordset.Fields(0)
  62.    objRecordset.MoveNext
  63. Loop
  64. objRecordset.Close
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72. 'Debug.Print "----------------------------------------------------------------------"
  73. '
  74. '' Debug.Print "UBound(Kunden): " & UBound(Kunden)
  75. 'For i = 0 To UBound(Kunden) - 1
  76. '    Debug.Print "Kunde: " & Kunden(i)
  77. 'Next i
  78. 'Debug.Print "--------------- " & Now() & " -------------------------"
  79.  
  80. ' sqlString = "SELECT count(*) from [Auftragseingang$] WHERE Kunde='" & Kunden(0) & "' AND Datum is not null"
  81.  
  82. '''''   This is lame.  Be ashamed of yourself
  83.  
  84. For i = 0 To UBound(Kunden) - 1
  85.     Debug.Print Kunden(i)
  86.     For j = 0 To UBound(Mitarbeiter) - 1
  87.         sqlString = "SELECT count(Datum) from [Auftragseingang$] WHERE Kunde='" & Kunden(i) & "' AND ([1# Mitarbeiter] = '" & Mitarbeiter(j) & "' OR [2# Mitarbeiter] = '" & Mitarbeiter(j) & "') AND Datum is not null"
  88.          objRecordset.Open sqlString & " ", objConnection, adOpenStatic, adLockOptimistic, adCmdText
  89.          ' Debug.Print Kunden(i) & " : " & Mitarbeiter(j) & " : " & objRecordset.Fields(0)
  90.         objRecordset.Close
  91.     Next j
  92. Next i
  93.  
  94. Debug.Print "--------------- " & Now() & " -------------------------"
  95.  
  96.  
  97.  
  98. objConnection.Close
  99.  
  100. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement