Hello Friends,
As part of my DB project, I often use
VBA to automate append queries for my users.
This works really well, but I have a situation which is a bit complex for me to get my head around.
My DB contains a module with three tables:
tblProjects
tblProjectTimelines (Stages of the Project)
tblProjectNotes (Memos and Documents)
One Project can have many timelines (linked by projectID)
One Timeline can have many notes (linked by projectTimelineID)
I have a system where "Projects" can be created from a set of Pre-fabricated rules. These "Pre-Fabs" are stored in three tables
tblProjects_Prefabs
tblProjectTL_Prefabs
tblProjectNotes_Prefabs
Again, the relationship is as it is before.
I have a form where the user can click a button to select a project style and save themselves having to work through adding each step manually.
So,
I callback to the record I've just created with:
(There are not many users, so the Date and time seems to be a safe way to get the ID I've just created).
I then run this:
Which works just fine... the new Project gets populated with all of the stages from the prefab.
...and then I run into a wall! :banghead:
How do I loop through each NEW record in tblProjectTimelines; and input the pre-staged notes from the corresponding tblProjectNotes_Prefabs that goes with each prefabricated Timeline within the project?
I've attached a cut out of this module - if anyone can comment....
Thank you!
As part of my DB project, I often use
Code:
Insert Into
This works really well, but I have a situation which is a bit complex for me to get my head around.
My DB contains a module with three tables:
tblProjects
tblProjectTimelines (Stages of the Project)
tblProjectNotes (Memos and Documents)
One Project can have many timelines (linked by projectID)
One Timeline can have many notes (linked by projectTimelineID)
I have a system where "Projects" can be created from a set of Pre-fabricated rules. These "Pre-Fabs" are stored in three tables
tblProjects_Prefabs
tblProjectTL_Prefabs
tblProjectNotes_Prefabs
Again, the relationship is as it is before.
I have a form where the user can click a button to select a project style and save themselves having to work through adding each step manually.
So,
Code:
Dim intProjectPrefabID, intCustID, intStaffID As Integer
Dim sql, strProjectStatus, strProjectContact, strDate As String
'the ints here are defined by some forms on the box, you get the idea
sql = ""
sql = sql & "INSERT INTO tblProjects ( ProjectTitle, ProjectBrief, ProjectType, customerID, staffID, ProjectStatus, ProjectContact, CreatedDate ) "
sql = sql & "SELECT tblProjects_Prefabs.ProjectTitle, tblProjects_Prefabs.ProjectBrief, tblProjects_Prefabs.ProjectType, " & intCustID & " AS customerid, " & intStaffID & " AS staffid, '" & strProjectStatus & "' AS ProjectStatus, '" & strProjectContact & "' AS ProjectContact, #" & strDate & "# AS CreatedDate "
sql = sql & "FROM tblProjects_Prefabs "
sql = sql & "WHERE (((tblProjects_Prefabs.ProjectPrefabID)=" & intProjectPrefabID & "));"
I callback to the record I've just created with:
Code:
Dim newProj As Integer
newProj = DLookup("ProjectID", "tblProjects", "[CreatedDate] = #" & strDate & "#")
(There are not many users, so the Date and time seems to be a safe way to get the ID I've just created).
I then run this:
Code:
sql = ""
sql = sql & "INSERT INTO tblProjectTimelines ( projectID, SuggestedTimescale, TimeLineTitle, TimeLineMemo, StageLevel, TimeLineCreated, staffID ) "
sql = sql & "SELECT " & newProj & " AS projectID, tblProjectTL_Prefabs.SuggestedTimescale, tblProjectTL_Prefabs.TimeLineTitle, tblProjectTL_Prefabs.TimeLineMemo, tblProjectTL_Prefabs.StageLevel, #" & strDate & "# AS TimeLineCreated, " & intStaffID & " AS staffID "
sql = sql & "FROM tblProjectTL_Prefabs "
sql = sql & "WHERE (((tblProjectTL_Prefabs.Project_PrefabID)= " & intProjectPrefabID & "));"
Which works just fine... the new Project gets populated with all of the stages from the prefab.
...and then I run into a wall! :banghead:
How do I loop through each NEW record in tblProjectTimelines; and input the pre-staged notes from the corresponding tblProjectNotes_Prefabs that goes with each prefabricated Timeline within the project?
I've attached a cut out of this module - if anyone can comment....

Thank you!