Ich habe eine Access-Back-End-Datenbank mit 7 verschachtelt, verwandten Tabellen: Kunden, Projekten, Projektziele, Tor Impediments, Impediment Ursachen, mögliche Lösungen und notwendige Maßnahmen oder Ressourcen. Jeder Kunde kann mehrere Projekte haben. Jedes Projekt kann in Zielen zu Aktionen mehrere Datensätze enthalten.Export verschachtelte Tabellen, um neuen Backend
Ich möchte ein Client-Projekt mit seinen verschachtelten Tabellen in ein leeres Backend mit genau der gleichen Struktur exportieren, damit der Client, der mit Front- und Backend geliefert wird, die Informationen überprüfen und Änderungen vornehmen kann. Wenn der Client Änderungen vorgenommen hat, möchte ich die Änderungen wieder in die master-Datenbank importieren und die vorhandenen Daten ersetzen.
Clients verfügt über die üblichen persönlichen Daten. Projekte haben acht Felder einschließlich einer verknüpften ID zu Clients. Jede Tabelle von Zielen Aktionen hat ein Auto Primärschlüssel nummeriert, ein ID-Feld auf den Primärschlüssel der Tabelle oben verlinkten, 100 Zeichen kurze Beschreibung, ein langes Feld für Notizen, eine Nummer für Priorität oder gewichtete Bedeutung und ein Feld Ja/Nein für gelöst oder abgeschlossen. Jeder kann zwischen 1 und 10 Datensätze haben. Es gibt 94 Datensätze in dem Beispieldatensatz, mit dem ich arbeite.
Es ist leicht genug, um das Projekt und die dazugehörigen Daten aus der Datenbank mit einer Abfrage zu extrahieren; aber ich habe Probleme, den effizientesten Weg zu finden, es in das leere Backend einzufügen. Ich habe ein paar Unterprogramme unter einer Export-Schaltfläche gestartet, um die Datentabelle nach Tabelle zu übertragen, so dass ich mit den geänderten Beziehungen umgehen konnte, die durch die Neunummerierung der Primärschlüssel verursacht wurden. aber ich würde gerne den gesamten Prozess auf einen Schlag erledigen, wenn möglich. Ich habe eine riesige Back-End-Datei mit einem fehlerhaften Versuch bei einer While NOT rsSource.EOF - Wend-Routine erstellt. Irgendwelche Vorschläge dankbar erhalten.
********************************-Code ************* *********************
Private Sub Command316_Click()
' SelectedClient and SelectedProject are Public Integer variables
' To be used in For...Next loops
Dim i, iNumRecs, intGoal, intImped, intCause, intSolution, intAction As Integer
Dim SQLstr As String
'Open source database
Dim dbSource As Database
Set dbSource = CurrentDb
'Open dest database
Dim dbDestination As Database
Set dbDestination = DAO.OpenDatabase("C:\Prosolve\Temp\Prosolve_BE.accdb")
' Select Project to be transferred
' Might be easier to work with if everything NOT selected at once
SQLstr = "SELECT Clients.ClientID, Clients.ContactFirstName, Clients.ContactLastName, Clients.Address, Clients.City, Clients.StateOrProvince, Clients.PostalCode, "
SQLstr = SQLstr + "Clients.Country, Clients.EmailAddress, Clients.CompanyName, Clients.PhoneNumber, Clients.CellNumber, Clients.BillingRate, Clients.TaxPayable, Clients.Discount, "
SQLstr = SQLstr + "Projects.ProjectID, Projects.ClientID, Projects.ProjectName, Projects.ProjectOwner, Projects.ProjectDescription, Projects.EmployeeID, Projects.Priority, Projects.TotalBilled, "
SQLstr = SQLstr + "Goals.GoalID, Goals.ProjectID, Goals.Goal, Goals.Notes, Goals.Owners, Goals.Gpriority, "
SQLstr = SQLstr + "Impediments.ImpedID, Impediments.IgoalID, Impediments.Impediment, Impediments.Notes, Impediments.Iweight, Impediments.Resolved, "
SQLstr = SQLstr + "Causes.CauseID, Causes.cimpedID, Causes.cause, Causes.Notes, Causes.cweight, Causes.resolved, "
SQLstr = SQLstr + "Solutions.SolutionID, Solutions.ScauseID, Solutions.Solution, Solutions.Notes, Solutions.Sweight, Solutions.Implemented, "
SQLstr = SQLstr + "Actions.ActionID, Actions.AsolutionID, Actions.Action, Actions.Notes, Actions.Priority, Actions.Completed "
SQLstr = SQLstr + "FROM ((Clients INNER JOIN Projects ON Clients.ClientID = Projects.ClientID) "
SQLstr = SQLstr + "INNER JOIN ((Goals INNER JOIN Impediments ON Goals.GoalID = Impediments.IgoalID) "
SQLstr = SQLstr + "INNER JOIN (Causes INNER JOIN Solutions ON Causes.causeID = Solutions.ScauseID) "
SQLstr = SQLstr + "ON Impediments.ImpedID = Causes.cimpedID) ON Projects.ProjectID = Goals.ProjectID) "
SQLstr = SQLstr + "INNER JOIN Actions ON Solutions.SolutionID = Actions.AsolutionID "
SQLstr = SQLstr + "WHERE Clients.ClientID = " & SelectedClient & " AND Projects.ProjectID = " & SelectedProject & " ;"
'Open source recordset
Dim rsSource As Recordset
Set rsSource = dbSource.OpenRecordset(SQLstr, dbOpenDynaset)
'Open dest recordset
Dim rsDestination As Recordset
Set rsDestination = dbDestination.OpenRecordset("Clients", dbOpenDynaset)
'Loop through source recordset
'While Not rsSource.EOF
'Look for record in dest recordset
rsDestination.FindFirst "ContactFirstName = '" & rsSource.Fields("ContactFirstName") & "'"
'& " AND ContactLastName = " & rsSource.Fields("ContactLastName") & ""
'If not found, copy record
'Works okay
If rsDestination.NoMatch Then
rsDestination.AddNew
rsDestination.Fields("ContactFirstName") = rsSource.Fields("ContactFirstName")
rsDestination.Fields("ContactLastName") = rsSource.Fields("ContactLastName")
rsDestination.Fields("Address") = rsSource.Fields("Address")
rsDestination.Fields("City") = rsSource.Fields("City")
rsDestination.Fields("StateOrProvince") = rsSource.Fields("StateOrProvince")
rsDestination.Fields("PostalCode") = rsSource.Fields("PostalCode")
rsDestination.Fields("Country") = rsSource.Fields("Country")
rsDestination.Fields("EmailAddress") = rsSource.Fields("EmailAddress")
rsDestination.Fields("CompanyName") = rsSource.Fields("CompanyName")
rsDestination.Fields("PhoneNumber") = rsSource.Fields("PhoneNumber")
rsDestination.Fields("CellNumber") = rsSource.Fields("CellNumber")
rsDestination.Fields("BillingRate") = rsSource.Fields("BillingRate")
rsDestination.Fields("TaxPayable") = rsSource.Fields("TaxPayable")
rsDestination.Fields("Discount") = rsSource.Fields("Discount")
rsDestination.Update
Else
MsgBox "Record alreasy exists"
End If
'Works okay
Set rsDestination = dbDestination.OpenRecordset("Projects", dbOpenDynaset)
rsDestination.FindFirst "ClientID = 1"
If rsDestination.NoMatch Then
rsDestination.AddNew
rsDestination.Fields("ClientID") = 1
rsDestination.Fields("ProjectName") = rsSource.Fields("ProjectName")
rsDestination.Fields("ProjectOwner") = rsSource.Fields("ProjectOwner")
rsDestination.Fields("ProjectDescription") = rsSource.Fields("ProjectDescription")
rsDestination.Fields("EmployeeID") = rsSource.Fields("EmployeeID")
rsDestination.Fields("Priority") = rsSource.Fields("Projects.Priority")
rsDestination.Fields("TotalBilled") = rsSource.Fields("TotalBilled")
rsDestination.Update
Else
MsgBox "Record alreasy exists"
End If
' Try to find number of Goals for a For ... Next procedure
' Not counting Goals in Query. Will cause problems later when 2 or more client have same ProjectID
iNumRecs = DCount("ProjectID", "Goals", "ProjectID = " & SelectedProject & "")
'Here we need to copy all goals for projectID = 1 from 1 to number of goals'
' Once this is done successfully the process can be repeated for tables below it
'Loop through source recordset
'Currently copies 6 x first goal. rsSource.Movenext not working.
Set rsDestination = dbDestination.OpenRecordset("Goals", dbOpenDynaset)
rsDestination.FindFirst "ProjectID = " & SelectedProject & ""
If rsDestination.NoMatch Then
For i = 1 To iNumRecs
rsDestination.AddNew
rsDestination.Fields("ProjectID") = SelectedProject
rsDestination.Fields("Goal") = rsSource.Fields("Goal")
rsDestination.Fields("Notes") = rsSource.Fields("Goals.Notes")
rsDestination.Fields("Owners") = rsSource.Fields("Owners")
rsDestination.Fields("Gpriority") = rsSource.Fields("Gpriority")
rsDestination.Update
rsSource.MoveNext
Next
Else
MsgBox "Record alreasy exists"
End If
MsgBox "Procedure successfully completed to this point"
End Sub
********************** ********** End-Code **********************************
Was haben Sie bisher versucht? Bitte zeigen Sie einen Code von Ihnen. Es ist ziemlich schwer mit so wenig Details über die eigentliche Programmierung zu helfen. –
Entschuldigung. Ein fehlgeleiteter Versuch, knapp zu sein. Der obige Code funktioniert bis zum Kopieren von Zielen. Es kopiert 6 x das erste Ziel, da das Movenext nicht so zu funktionieren scheint, wie ich es auf dem rsSource-Recordset erwartet hatte. –