根据另一个记录集

时间:2018-05-11 06:10:17

标签: ms-access access-vba

我有两个表(让我们称之为参数1和2),它们与第三个表(选项)有很多关系。我需要将第三个表记录分为三组:

  1. 与[特定参数1记录]完全相关的那些,
  2. 与[特定参数2记录]和
  3. 完全相关的那些
  4. 与[特定参数1记录]和[特定参数]相关的那些 2记录]。
  5. 我可以忽略与其中任何一个都无关的选项记录。

    我需要能够指定哪个参数1和2记录在表单中应用(使用组合框),并让VBA在后台处理这三个列表,将它们更新为它们包含的选项记录是"使用"表格中的其他地方(带复选框)。

    冒着提出错误问题的风险我会提交我所拥有的代码 - 即使它不是失败的代码,只是一个没有&#的框架39; t甚至完成了调试。我根本没有完成它的工具,因为我不知道用什么方法/属性来做它,并且似乎无法在我自己的研究中找到答案迄今。即使您没有得到您确定为最佳做法的答案,也会感谢您将注意力转向其他资源。

    Function SetOptions()
    If IsNull(cmbParam1) Or IsNull(cmbParam2) Then
        MsgBox "You must select both an Param1 and a Param2!", vbCritical, "Wait!"
        Exit Function
    End If
    
    'Recordsets of allowed Options
    Dim Param1Opt, Param2Opt, OverlapOpt
    
    'create recordset of tblOption.Option(s) referenced in qryPr1Opt with Param1 from cmbParam1
    Param1Opt = CurrentDb.OpenRecordset("SELECT tblPr1Opt.Option FROM tblPr1Opt " &_
    "WHERE Param1 = '" & cmbParam1 & "';")
    'create recordset of tblOption.Option(s) referenced in qryPr2Opt with Param2 from cmbParam2
    Param2Opt = CurrentDb.OpenRecordset("SELECT tblPr2Opt.Option FROM tblPr2Opt " &_
    "WHERE Param2 = '" & cmbParam2 & "';")
    'create recordset of tblOption.Option(s) in qryOptOvrlp with Param2 and Param1 from form
    OverlapOpt = CurrentDb.OpenRecordset("SELECT qryOptOvrlp.Option FROM qryOptOvrlp " &_
    "WHERE Param1 = '" & cmbParam1 & "' AND Param2 = '" & cmbParam2 & "';")
    OverlapNum = Param1Num + Param2Num
    
    'Steps remaining:
    '1. Get Param1Opt and Param2Opt to only include Options not in overlap
    For Each oOpt In OverlapOpt
        For Each aOpt In Param1Opt
            If aOpt.Value = oOpt.Value Then
            'filter this record out of Param1Opt
            End If
        Next aOpt
        For Each gOpt In Param2Opt
            If gOpt.Value = oOpt.Value Then
            'filter this record out of Param2Opt
            End If
        Next gOpt
    Next oOpt
    
    '2. Get the data in Param1Opt, Param2Opt and OverlapOpt, as well as their
    'corresponding Nums to be accessible/editable in other functions/subs
    End Function
    

0 个答案:

没有答案