Prikazi cijelu temu 21.02.2022 12:26
Gjoreski Van mreze
Administrator
Registrovan od:02.02.2009
Lokacija:Ohrid Makedonija


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