Prikazi cijelu temu 22.07.2013 16:28
zxz Van mreze
Administrator
Registrovan od:03.02.2009
Lokacija:Tuzla


Predmet:Re: Spajanje arhiviranih baza
Stavi ovu proceduru pa pokreni.
U dir app. dobit ces file aaa.txt pa ga zakaci na forum.
PreuzmiIzvorni kôd (Visual Basic):
  1. Function KreirajTempZXZ()
  2. Dim wrk As Workspace
  3. Dim Db As Database, tmpBaza As Database
  4. Dim Rs As Recordset, tmpRs As Recordset
  5. Dim Fld As Field
  6. Dim OrgTabela As TableDef, TmpTabela As TableDef
  7. Dim ImeBaze As String, ImeTmpBaze As String
  8. Dim ImeFajla As String, SQL(1) As String
  9. Dim Prefiks As Integer
  10.  
  11.  
  12. Open Db_Putanja & "\aaa.txt" For Output Shared As #1
  13. DoCmd.SetWarnings False
  14. ImeTmpBaze = Db_Putanja & "tmp.mdb"
  15. If Dir(ImeTmpBaze) <> "" Then Kill ImeTmpBaze
  16. Set Db = CurrentDb()
  17. Set wrk = DBEngine.Workspaces(0)
  18. 'Tabela transakcije
  19. Set tmpBaza = wrk.CreateDatabase(ImeTmpBaze, dbLangGeneral)
  20. Set OrgTabela = Db.TableDefs("tblTransakcije")
  21. Set TmpTabela = tmpBaza.CreateTableDef("tblTransakcije")
  22. For Each Fld In OrgTabela.Fields
  23.     With TmpTabela
  24.     .Fields.Append .CreateField(Fld.Name, Fld.Type, Fld.Size)
  25.     End With
  26. Next Fld
  27. tmpBaza.TableDefs.Append TmpTabela
  28. Set OrgTabela = Nothing
  29. Set TmpTabela = Nothing
  30. 'tabela ulazizlaz
  31. Set OrgTabela = Db.TableDefs("tblUlazIzlaz")
  32. Set TmpTabela = tmpBaza.CreateTableDef("tblUlazIzlaz")
  33. For Each Fld In OrgTabela.Fields
  34.     With TmpTabela
  35.     .Fields.Append .CreateField(Fld.Name, Fld.Type, Fld.Size)
  36.     End With
  37. Next Fld
  38. tmpBaza.TableDefs.Append TmpTabela
  39. Set OrgTabela = Nothing
  40. Set TmpTabela = Nothing
  41. 'Prenos podataka
  42. ImeFajla = Dir(DirPutanja, vbDirectory)
  43. Print #1, "-----Pije petlje ImeFajla----"
  44. Print #1, ImeFajla
  45.         Do While Len(ImeFajla) > 0
  46.             ImeFajla = Dir
  47.             Print #1, "-----Pije Ifa ImeFajla----"
  48.             Print #1, ImeFajla
  49.              If Right(ImeFajla, 3) = "Mdb" Then
  50.                 ImeBaze = DirPutanja & ImeFajla
  51.                
  52.                 Prefiks = Mid(ImeBaze, (Len(ImeBaze) - 8), 2)
  53.                      SQL(0) = "INSERT INTO tblTransakcije (IDTransakcije, Datum, Skladiste, IDdokumenta, BrDokumenta, " _
  54.                     & "PartnerID, RadniNalog, OperID, StatusTR, DatumU, Brisanje )IN '" & ImeTmpBaze _
  55.                     & "' SELECT " & Prefiks & "& [IDTransakcije] AS ID, Datum, Skladiste,IDdokumenta, " _
  56.                     & "BrDokumenta,PartnerID, RadniNalog, OperID, StatusTR,DatumU, Brisanje " _
  57.                     & "FROM tblTransakcije IN '" & ImeBaze & "'"
  58.                     DoCmd.RunSQL (SQL(0))
  59.                     SQL(1) = "INSERT INTO tblUlazIzlaz ( IDTransakcije, Sifra, Ulaz, Izlaz, Status, DatumU )IN '" & ImeTmpBaze _
  60.                         & "' SELECT " & Prefiks & " & [IDTransakcije] AS ID, Sifra, Ulaz, Izlaz, Status, DatumU " _
  61.                         & "FROM tblUlazIzlaz IN '" & ImeBaze & "'"
  62.                     DoCmd.RunSQL (SQL(1))
  63.                     Print #1, "-----Poslije ifa----"
  64.                     Print #1, ImeFajla & vbTab & ImeBaze & vbTab & vbTab & Prefiks & vbTab
  65.              End If
  66.         Loop
  67.  'MsgBox ImeFajla
  68. 'ImeFajla = Dir
  69.  'MsgBox ImeFajla
  70. Set tmpBaza = Nothing
  71. Set Db = Nothing
  72. DoCmd.SetWarnings True
  73. Close #1
  74. End Function

Podrška samo putem foruma, jer samo tako i ostali imaju koristi od toga.