我有两个组合框,Combo_A 在 Combo_B 中设置查询字符串。在从 combo_B 中选择一个选项并点击 go 按钮后,将根据 Combo_A 中的选择执行两个查询之一。如果在 Combo_A 中选择了选项 1,则执行按钮执行查询 A,如果在 Combo_A 中选择了选项 2,则执行按钮执行查询 B。这一切都很好,它通过将查询名称分配给变量然后执行一个 DoCmd.OpenQuery_Click。
我的问题是我想更进一步。我想在选中复选框时将上面的结果与另一个查询交叉引用,当未选中时,它的行为需要与我目前设计的完全相同。我知道我可以创建查询,但使用 vba 不太舒服。我可以使用代表查询的变量名来加入另一个查询吗?到目前为止,这是我的 vba 代码。
Option Compare Database
Private Sub AgencyorCarrierSelection_AfterUpdate()
If AgencyorCarrierSelection = "By Insurance Carrier" Then
Combo7.Visible = True
Text13.Value = "Select of of the following Carriers:"
Text13.Visible = True
Combo7.RowSource = "SELECT [tblRefInsuranceCarriers].[InsuranceCarrierID], [tblRefInsuranceCarriers].[CarrierName] FROM [tblRefInsuranceCarriers] ORDER BY [CarrierName];"
Else
Combo7.Visible = True
Text13.Value = "Select of of the following Agencies:"
Text13.Visible = True
Combo7.RowSource = "SELECT [tblRefInsuranceAgencies].[InsuranceAgencyID], [tblRefInsuranceAgencies].[AgencyName] FROM [tblRefInsuranceAgencies] ORDER BY [AgencyName]"
End If
End Sub
Private Sub lblSwitchboard_Click()
DoCmd.OpenForm "switchboard", acNormal
DoCmd.Close acForm, "frmInsuranceInformationConnect"
End Sub
Private Sub RunAgencyorCarrierQuery_Click()
On Error GoTo Err_RunAgencyorCarrierQuery_Click
Dim stDocName As String
If AgencyorCarrierSelection = "By Insurance Carrier" Then
stDocName = "qryInsuranceCarrierAgentPremiumBreakout_Carrier"
Else
stDocName = "qryInsuranceCarrierAgentPremiumBreakout_Agency"
End If
DoCmd.OpenQuery stDocName, acNormal, acEdit
Exit_RunAgencyorCarrierQuery_Click:
Exit Sub
Err_RunAgencyorCarrierQuery_Click:
MsgBox Err.Description
Resume Exit_RunAgencyorCarrierQuery_Click
End Sub