Mainform选项卡控件将值传递给选择案例的子表单变量 [英] Mainform tab control passing value to subform variable for select case
问题描述
最近三个小时,我一直在搜索此文件,因此,如果有人提出并回答了此问题,我们感到抱歉,但是找不到解决方案.
I've been searching this for the last three hours, so I'm sorry if this has been asked and answered, but I can't find the solution.
我有一个主窗体,frmPHDLP
和子窗体(连续数据表)frmPHDUpdate
.两者都不是绑定形式. frmPHDLP
上有一个选项卡控件,可显示现实世界中的办公室位置.子窗体将根据所选选项卡显示每个位置的员工列表.我在VBA的子窗体中设置RecordSource.
I have a mainform, frmPHDLP
and subform (continuous datasheet) frmPHDUpdate
. Neither are bound forms. frmPHDLP
has a tab control on it which displays real world office locations. The subform will display a list of employees at each location based on the tab selected. I am setting the RecordSource in the subform in VBA.
第一个标签可以完美显示.问题是,当我在主窗体上选择一个新选项卡时,无法获得子窗体以使用新位置重新查询SQL. SQL语句内置在子窗体的Form_Current
事件中.
The first tab works perfect. The problem is, when I choose a new tab on the mainform, I cannot get the subform to requery the SQL with the new location. The SQL statement is built in the Form_Current
event of the subform.
显然运行Me!frmPHDUpdate.Form.Requery
不会在子窗体上触发Form_Current
事件.因为为什么会这样?
Apparently running Me!frmPHDUpdate.Form.Requery
does not fire the Form_Current
event on the subform. Because why would it?
三个小时.娜达感谢您的帮助.
THREE HOURS. Nada. Thanks for any help.
frmPHDLP代码:
frmPHDLP Code:
Private Sub tabOffices_Change()
Me!frmPCLPUpdateSF.Requery
End Sub
frmPHD更新代码:
frmPHDUpdate Code:
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
推荐答案
您应该使代码更具模块化.另外,您不应在Form_Current上更改表单记录源,因为那样会重新查询表单,并触发另一个电流,并触发无限循环.这可能是由于Access避免了无限循环所致.
You should make your code more modular. Also, you should not change the forms recordsource on Form_Current, since that requeries the form, and triggers another current, and that triggers an infinite loop. This might all be caused by Access avoiding that infinite loop.
frmPHD更新代码:
frmPHDUpdate Code:
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代码:
frmPHDLP Code:
Private Sub tabOffices_Change()
Me!frmPCLPUpdateSF.Form.BuildSQL
End Sub
或更妙的是:将case语句移到SQL子窗体中:
Or, even better: move your case statement to the subforms SQL:
作为frmPHDUpdate的记录源
As the record source for 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
);
这篇关于Mainform选项卡控件将值传递给选择案例的子表单变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!