【发布时间】:2021-04-16 17:42:39
【问题描述】:
如何使用代码生成的数据和用户输入将记录添加到 deploymentStep 表和 deploymentPlan 表?
我有如下表格
PillarTeamDeploymentSteps
| pillarTeam | pillarTeamStep | other info |
|---|---|---|
| team 1 | step 1 | |
| team 1 | step 2 | |
| team 1 | step 3 | |
| team 1 | step 4 | |
| team 2 | step 1 | |
| team 2 | step 2 | |
| team 2 | step 3 | |
| team 2 | step 4 | |
| team 2 | step 5 | |
| team 2 | step 6 |
和表的结构
部署步骤
| pillarTeam | pillarTeamStep | deployment | endDate |
|---|---|---|---|
部署计划
| pillarTeam | deployment | startDate | endDate |
|---|---|---|---|
使用表单我希望用户能够选择他们的团队并让它使用相应的pillarTeamSteps 自动填充文本字段。这可以在屏幕截图中看到。
在用户选择了一个团队并自动填充了步骤后,他们将在日期框中手动输入数据。从这里我想要一个按钮来添加记录。我正在使用以下代码来更新表单可见字段和值。每个团队最多只能走十步。
如何使用代码生成的数据和用户输入将记录添加到 deploymentStep 表和 deploymentPlan 表?
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
【问题讨论】: