Mainform 选项卡控件将值传递给 select 情况下的子窗体变量
Mainform tab control passing value to subform variable for select case
过去三个小时我一直在搜索这个问题,如果有人提出并回答了这个问题,我很抱歉,但我找不到解决方案。
我有一个主窗体,frmPHDLP
和子窗体(连续数据表)frmPHDUpdate
。绑定形式也不是。 frmPHDLP
上面有一个选项卡控件,可以显示真实世界的办公室位置。子表单将根据所选选项卡显示每个位置的员工列表。我在 VBA 的子窗体中设置 RecordSource。
第一个选项卡完美无缺。问题是,当我在主窗体上选择一个新选项卡时,我无法让子窗体重新查询新位置的 SQL。 SQL语句内置于子窗体的Form_Current
事件中。
显然 运行 Me!frmPHDUpdate.Form.Requery
不会触发子表单上的 Form_Current
事件。因为为什么会这样?
三个小时。纳达。感谢您的帮助。
frmPHDLP 代码:
Private Sub tabOffices_Change()
Me!frmPCLPUpdateSF.Requery
End Sub
frmPHD更新码:
Private Sub Form_Current()
Dim strSearch As String
Dim strSQL As String
Select Case Me.Parent!tabOffices.Value
Case 0
strSearch = "8401"
Case 1
strSearch = "8400"
Case 2
strSearch = "8403"
Case 3
strSearch = "8402"
Case 4
strSearch = "8404"
Case 5
strSearch = "8405"
Case 6
strSearch = "8413"
Case 7
strSearch = "8411"
End Select
strSQL = "SELECT tblEmployee.ID, tblEmployee.[LastName] & "", "" & [FirstName] AS EmpName, tblPHDLProgram.MemberOfPHDL, tblOffices.OfficeID FROM tblOffices INNER JOIN (tblPHDLP RIGHT JOIN tblEmployee ON tblPHDLP.ID = tblEmployee.ID) ON tblOffices.ID = tblEmployee.Office WHERE (((tblOffices.OfficeID)= " & strSearch & "));"
Me.RecordSource = strSQL
End Sub
查看 MasterLinkFields/ChildLinkFields。
我猜你可以使用 tabOffices 和 OfficeID 并删除所有这些代码。
您应该使您的代码更加模块化。此外,您不应更改 Form_Current 上的表单记录源,因为这会重新查询表单并触发另一个电流,从而触发无限循环。这可能都是由于 Access 避免了无限循环造成的。
frmPHD更新码:
Public Sub BuildSQL()
Dim strSearch As String
Dim strSQL As String
Select Case Me.Parent!tabOffices.Value
Case 0
strSearch = "8401"
Case 1
strSearch = "8400"
Case 2
strSearch = "8403"
Case 3
strSearch = "8402"
Case 4
strSearch = "8404"
Case 5
strSearch = "8405"
Case 6
strSearch = "8413"
Case 7
strSearch = "8411"
End Select
strSQL = "SELECT tblEmployee.ID, tblEmployee.[LastName] & "", "" & [FirstName] AS EmpName, tblPHDLProgram.MemberOfPHDL, tblOffices.OfficeID FROM tblOffices INNER JOIN (tblPHDLP RIGHT JOIN tblEmployee ON tblPHDLP.ID = tblEmployee.ID) ON tblOffices.ID = tblEmployee.Office WHERE (((tblOffices.OfficeID)= " & strSearch & "));"
Me.RecordSource = strSQL
End Sub
Private Sub Form_Load()
Me.BuildSQL
End Sub
frmPHDLP 代码:
Private Sub tabOffices_Change()
Me!frmPCLPUpdateSF.Form.BuildSQL
End Sub
或者,甚至更好:将您的 case 语句移动到子表单 SQL:
作为frmPHDUpdate的记录源
SELECT tblEmployee.ID, tblEmployee.[LastName] & "", "" & [FirstName] AS EmpName, tblPHDLProgram.MemberOfPHDL, tblOffices.OfficeID
FROM tblOffices
INNER JOIN (tblPHDLP RIGHT JOIN tblEmployee ON tblPHDLP.ID = tblEmployee.ID) ON tblOffices.ID = tblEmployee.Office
WHERE tblOffices.OfficeID = Switch(
Forms!frmPHDLP!tabOffices = 0, 8401,
Forms!frmPHDLP!tabOffices = 1, 8400,
Forms!frmPHDLP!tabOffices = 2, 8403,
Forms!frmPHDLP!tabOffices = 3, 8402,
Forms!frmPHDLP!tabOffices = 4, 8404,
Forms!frmPHDLP!tabOffices = 5, 8405,
Forms!frmPHDLP!tabOffices = 6, 8413,
Forms!frmPHDLP!tabOffices = 7, 8411
);
过去三个小时我一直在搜索这个问题,如果有人提出并回答了这个问题,我很抱歉,但我找不到解决方案。
我有一个主窗体,frmPHDLP
和子窗体(连续数据表)frmPHDUpdate
。绑定形式也不是。 frmPHDLP
上面有一个选项卡控件,可以显示真实世界的办公室位置。子表单将根据所选选项卡显示每个位置的员工列表。我在 VBA 的子窗体中设置 RecordSource。
第一个选项卡完美无缺。问题是,当我在主窗体上选择一个新选项卡时,我无法让子窗体重新查询新位置的 SQL。 SQL语句内置于子窗体的Form_Current
事件中。
显然 运行 Me!frmPHDUpdate.Form.Requery
不会触发子表单上的 Form_Current
事件。因为为什么会这样?
三个小时。纳达。感谢您的帮助。
frmPHDLP 代码:
Private Sub tabOffices_Change()
Me!frmPCLPUpdateSF.Requery
End Sub
frmPHD更新码:
Private Sub Form_Current()
Dim strSearch As String
Dim strSQL As String
Select Case Me.Parent!tabOffices.Value
Case 0
strSearch = "8401"
Case 1
strSearch = "8400"
Case 2
strSearch = "8403"
Case 3
strSearch = "8402"
Case 4
strSearch = "8404"
Case 5
strSearch = "8405"
Case 6
strSearch = "8413"
Case 7
strSearch = "8411"
End Select
strSQL = "SELECT tblEmployee.ID, tblEmployee.[LastName] & "", "" & [FirstName] AS EmpName, tblPHDLProgram.MemberOfPHDL, tblOffices.OfficeID FROM tblOffices INNER JOIN (tblPHDLP RIGHT JOIN tblEmployee ON tblPHDLP.ID = tblEmployee.ID) ON tblOffices.ID = tblEmployee.Office WHERE (((tblOffices.OfficeID)= " & strSearch & "));"
Me.RecordSource = strSQL
End Sub
查看 MasterLinkFields/ChildLinkFields。
我猜你可以使用 tabOffices 和 OfficeID 并删除所有这些代码。
您应该使您的代码更加模块化。此外,您不应更改 Form_Current 上的表单记录源,因为这会重新查询表单并触发另一个电流,从而触发无限循环。这可能都是由于 Access 避免了无限循环造成的。
frmPHD更新码:
Public Sub BuildSQL()
Dim strSearch As String
Dim strSQL As String
Select Case Me.Parent!tabOffices.Value
Case 0
strSearch = "8401"
Case 1
strSearch = "8400"
Case 2
strSearch = "8403"
Case 3
strSearch = "8402"
Case 4
strSearch = "8404"
Case 5
strSearch = "8405"
Case 6
strSearch = "8413"
Case 7
strSearch = "8411"
End Select
strSQL = "SELECT tblEmployee.ID, tblEmployee.[LastName] & "", "" & [FirstName] AS EmpName, tblPHDLProgram.MemberOfPHDL, tblOffices.OfficeID FROM tblOffices INNER JOIN (tblPHDLP RIGHT JOIN tblEmployee ON tblPHDLP.ID = tblEmployee.ID) ON tblOffices.ID = tblEmployee.Office WHERE (((tblOffices.OfficeID)= " & strSearch & "));"
Me.RecordSource = strSQL
End Sub
Private Sub Form_Load()
Me.BuildSQL
End Sub
frmPHDLP 代码:
Private Sub tabOffices_Change()
Me!frmPCLPUpdateSF.Form.BuildSQL
End Sub
或者,甚至更好:将您的 case 语句移动到子表单 SQL:
作为frmPHDUpdate的记录源
SELECT tblEmployee.ID, tblEmployee.[LastName] & "", "" & [FirstName] AS EmpName, tblPHDLProgram.MemberOfPHDL, tblOffices.OfficeID
FROM tblOffices
INNER JOIN (tblPHDLP RIGHT JOIN tblEmployee ON tblPHDLP.ID = tblEmployee.ID) ON tblOffices.ID = tblEmployee.Office
WHERE tblOffices.OfficeID = Switch(
Forms!frmPHDLP!tabOffices = 0, 8401,
Forms!frmPHDLP!tabOffices = 1, 8400,
Forms!frmPHDLP!tabOffices = 2, 8403,
Forms!frmPHDLP!tabOffices = 3, 8402,
Forms!frmPHDLP!tabOffices = 4, 8404,
Forms!frmPHDLP!tabOffices = 5, 8405,
Forms!frmPHDLP!tabOffices = 6, 8413,
Forms!frmPHDLP!tabOffices = 7, 8411
);