如何使用代码和用户输入生成的数据将记录添加到DeploymentStep表和DeploymentPlan表中?
我有如下表格
支柱团队部署步骤
支柱团队 | 支柱团队步骤 | 其他资讯 |
---|---|---|
1队 | 第1步 | |
1队 | 第2步 | |
1队 | 第三步 | |
1队 | 步骤4 | |
2队 | 第1步 | |
2队 | 第2步 | |
2队 | 第三步 | |
2队 | 步骤4 | |
2队 | 步骤5 | |
2队 | 步骤6 |
和表的结构
部署步骤
支柱团队 | 支柱团队步骤 | 部署 | 结束日期 |
---|---|---|---|
部署计划
支柱团队 | 部署 | 开始日期 | 结束日期 |
---|---|---|---|
使用表格,我希望用户能够选择他们的团队,并让它使用相应的columnTeamSteps自动填充文本字段。可以在屏幕截图中看到。
After the user has selected a team and the steps have autopopulated they would manually input data in the date boxes. From here i'd like a button press to add the records. I am using the following code to update the forms visibile fields and values. There will be only a max steps of ten per team.
How can I use the data generated by the code and the user input to add the records to the deploymentStep table and to the deploymentPlan table?
Private Sub pillarTeam_AfterUpdate()
Dim db As DAO.Database
Dim RS As DAO.Recordset
Dim deploymentSteps As DAO.Recordset
Set db = CurrentDb
strSQL = "SELECT PillarTeamDeploymentSteps.pillarTeam, PillarTeamDeploymentSteps.pillarTeamStep, PillarTeamDeploymentSteps.deploymentType FROM PillarTeamDeploymentSteps WHERE (((PillarTeamDeploymentSteps.pillarTeam)=" & Me.pillarTeam & "))"
Debug.Print (strSQL)
Set RS = db.OpenRecordset(strSQL)
If Not (RS.EOF) Then
RS.MoveLast
RS.MoveFirst
End If
'setting visible controls
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag < RS.RecordCount + 1 Or (ctl.Tag < RS.RecordCount + 21 And ctl.Tag >= 20) Then
ctl.Visible = True
Else
ctl.Visible = False
End If
Next ctl
With RS
If Not .BOF And Not .EOF Then
.MoveLast
.MoveFirst
While (Not .EOF)
Debug.Print (RS.AbsolutePosition)
'populating deployment steps
For Each ctl In Me.Controls
If ctl.Tag = RS.AbsolutePosition Then
ctl.Value = RS.Fields("pillarTeamStep")
End If
Next ctl
.MoveNext
Wend
End If
.Close
End With
Set RS = Nothing
Set db = Nothing
Suggest binding form to deploymentPlan and have a subform bound to deploymentStep.
To 'batch' create records, use an INSERT SELECT action SQL.
CurrentDb.Execute "INSERT INTO deploymentStep(pillarTeam, pillarTeamStep, deployment) " & _
"SELECT " & Me.tbxTeam & " AS T, pillarTeamStep, " & Me.tbxDeploymentID & " AS D " & _
"FROM PillarTeamDeploymentSteps " & _
"WHERE pillarTeam=" & Me.tbxTeam
This assumes pillarTeam and deployment are numeric identifiers such as Autonumber type. If not, then use apostrophe delimiters.
这里的技巧是首先保存“父” deploymentPlan记录,并获取该记录标识符以另存为DeploymentStep中的外键。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句