Warning: Illegal string offset 'status' in /home2/icentarb/public_html/icentar/print.php on line 190

Warning: Illegal string offset 'status' in /home2/icentarb/public_html/icentar/print.php on line 190

Warning: Illegal string offset 'status' in /home2/icentarb/public_html/icentar/print.php on line 190

Warning: Illegal string offset 'status' in /home2/icentarb/public_html/icentar/print.php on line 190

Warning: Illegal string offset 'status' in /home2/icentarb/public_html/icentar/print.php on line 190
iCentar » Racunari i oprema » Programirannje i baze podataka » Access » Kopiranje tabela iz jedne baze u drugu
Amelasar 19.02.2022 22:59
Predmet:Kopiranje tabela iz jedne baze u drugu

Sa ovim funkcijama napravim novu bazu i kopiram tabele.
Medjutim problem mi je sto se ne kopiraju veze (relationships).
Takodjer bilo bi dobro da odredim koje tabele ce se kopirati sa podacima a koje samo struktura.

Trazila sam po forumu ali nisam se uspjela snaci. Ima li neko ideju?

PreuzmiIzvorni kôd (Text):
  1. Function makedb()
  2.    
  3.    Dim accessApp As Access.Application
  4.    Set accessApp = New Access.Application
  5.    
  6.    strDBPath = "D:\tblImport2022.mdb"
  7.    strDb = Dir(strDBPath)
  8.  
  9.    If Len(strDb) <> 0 Then
  10.     MsgBox "Baza postoji"
  11.     Else
  12.     Rem MsgBox "Baza ne postoji"
  13.     accessApp.DBEngine.CreateDatabase "D:\tblImport2022.mdb", DB_LANG_GENERAL
  14.     RunBackup
  15.    accessApp.Quit
  16.    Set accessApp = Nothing
  17. End If
  18.  
  19. End Function
  20.  
  21. Public Function RunBackup()
  22.  
  23.  Rem   DB_CopyTo = "D:\backup_" & Format(Now, "yymmdd_hhnn") & ".mdb"
  24.     DB_CopyTo = "D:\tblImport2022.mdb"
  25.    Rem  DBEngine.CreateDatabase DB_CopyTo, dbLangGeneral
  26.    
  27.     With CurrentDb
  28.         For Each t In .TableDefs
  29.             Select Case True
  30.             Case Left(t.Name, 1) = "~"
  31.             Case Left(t.Name, 4) = "msys"
  32.             Case Else
  33.                 .Execute "select * into [" & DB_CopyTo & "].[" & t.Name & "] from [" & t.Name & "]"
  34.             End Select
  35.         Next
  36.     End With
  37.    
  38. End Function
Prilozi:
KopirajBazu.rar (Velicina datoteke:88.50 KB)

Amelasar 21.02.2022 11:19
Predmet:Re:Kopiranje tabela iz jedne baze u drugu

PreuzmiIzvorni kôd (Text):
  1. DoCmd.TransferDatabase acExport, "Microsoft Access", "D:\tblImport2022.mdb", acTable, "tblTekucaGodina", "tblTekucaGodina", False
  2. DoCmd.TransferDatabase acExport, "Microsoft Access", "D:\tblImport2022.mdb", acTable, "tblOtpremnicaStavke", "tblOtpremnicaStavke", True
  3. DoCmd.TransferDatabase acExport, "Microsoft Access", "D:\tblImport2022.mdb", acTable, "tblOtpremnica", "tblOtpremnica", True

Na ovaj nacin kopiram tabele sa podacima ili bez, al relacije ne. Sad

Gjoreski 21.02.2022 12:26
Predmet:Re:Kopiranje tabela iz jedne baze u drugu

Eve probaj ova :
PreuzmiIzvorni kôd (Visual Basic):
  1. Public Function CreateAllRelations()
  2.  
  3.     Dim db As DAO.Database
  4.     Dim totalRelations As Integer
  5.    
  6.     Set db = CurrentDb()
  7.     totalRelations = db.Relations.Count
  8.     If totalRelations > 0 Then
  9.         For i = totalRelations - 1 To 0 Step -1
  10.             db.Relations.Delete (db.Relations(i).Name)
  11.         Next i
  12.         Debug.Print Trim(Str(totalRelations)) + " Relationships deleted!"
  13.     End If
  14.    
  15.     Debug.Print "Creating Relations..."
  16.    
  17.     ''==========================
  18.    ''Example
  19.    'Employee Master to Employee CheckIn
  20.    Debug.Print CreateRelation("Employee", "Code", _
  21.                                "CheckIn", "Code")
  22.    
  23.     ''Orders to Order Details
  24.    Debug.Print CreateRelation("Orders", "No", _
  25.                                "OrderDetails", "No")
  26.     ''==========================
  27.    
  28.     totalRelations = db.Relations.Count
  29.     Set db = Nothing
  30.    
  31.     Debug.Print Trim(Str(totalRelations)) + " Relationships created!"
  32.     Debug.Print "Completed!"
  33. End Function
  34.  
  35. Private Function CreateRelation(primaryTableName As String, _
  36.                                 primaryFieldName As String, _
  37.                                 foreignTableName As String, _
  38.                                 foreignFieldName As String) As Boolean
  39. On Error GoTo ErrHandler
  40.  
  41.     Dim db As DAO.Database
  42.     Dim newRelation As DAO.Relation
  43.     Dim relatingField As DAO.Field
  44.     Dim relationUniqueName As String
  45.    
  46.     relationUniqueName = primaryTableName + "_" + primaryFieldName + _
  47.                          "__" + foreignTableName + "_" + foreignFieldName
  48.    
  49.     Set db = CurrentDb()
  50.    
  51.     'Arguments for CreateRelation(): any unique name,
  52.    'primary table, related table, attributes.
  53.    Set newRelation = db.CreateRelation(relationUniqueName, _
  54.                             primaryTableName, foreignTableName)
  55.     'The field from the primary table.
  56.    Set relatingField = newRelation.CreateField(primaryFieldName)
  57.     'Matching field from the related table.
  58.    relatingField.ForeignName = foreignFieldName
  59.     'Add the field to the relation's Fields collection.
  60.    newRelation.Fields.Append relatingField
  61.     'Add the relation to the database.
  62.    db.Relations.Append newRelation
  63.    
  64.     Set db = Nothing
  65.    
  66.     CreateRelation = True
  67.        
  68. Exit Function
  69.  
  70. ErrHandler:
  71.     Debug.Print Err.Description + " (" + relationUniqueName + ")"
  72.     CreateRelation = False
  73. End Function

Gjoreski 21.02.2022 12:46
Predmet:Re:Kopiranje tabela iz jedne baze u drugu

Imas sistemska tabela: MSysRelationships
u njoj su smestene svi relacije

Amelasar 21.02.2022 13:28
Predmet:Re:Kopiranje tabela iz jedne baze u drugu

Ne dozvoljava kopiranje tabele MSysRelationships, nemam dozvole. Run-time error 3033.
Hvala na pomoci.

Gjoreski 22.02.2022 13:50
Predmet:Re:Kopiranje tabela iz jedne baze u drugu

Napravi tabela i popisi sve relacije , nakon to napravi petja i pozovi funkcija koja sam postavio