我正在开发一个应允许用户从列表框中选择代码的应用程序,并且该值应作为参数传递给与 SQL 查询绑定的子表单(连续),以使用从返回的值填充表单查询。
如何将父表单上的列表框与连续表单(子表单)联系起来,以便在子表单中注册列表框的更改并相应地重新填充它(子表单)?
下面的代码是我目前在父表单中触发子表单更改的代码。但是我仍然错过了用这个触发子表单中信息重新加载的地方。
存储过程
SELECT tblACCOUNT.ACCOUNT_LABEL, tblACCOUNTValue.[ACCOUNTVALUE_VALUE]
FROM ((tblUPS INNER JOIN tblProductUPS ON tblProductUPS.[PRODUCTUPS_UPS] = tblUPS.[UPS_CODE]) INNER JOIN tblACCOUNT ON tblUPS.UPS_ID = tblACCOUNT.ACCOUNT_UPSID) INNER JOIN tblACCOUNTValue ON tblACCOUNTVALUE.[ACCOUNTVALUE_ACCOUNTID]= tblACCOUNT.[ACCOUNT_ID]
WHERE TBLPRODUCTUPS.[PRODUCTUPS_PRODUCTID] = (SELECT tblProductLevel.[PRODUCTLEVEL_ID]
FROM tblProductLevel WHERE tblProductLevel.[PRODUCTLEVEL_Code] IN ( [UPSIDS])
);
这是我的子表单中的一个字段,我想将它作为查询的参数源绑定到我的查询。
Public Property Let qString(unstring As String)
If Not IsNull(unstring) And Len(unstring) > 0 Then
Currentstring = unstring
End If
End Property
下面的代码是我测试的父表单中的代码,它直接连接到我创建的查询并将参数直接传递给查询。但是,由于我的子表单本身与查询相关联,因此我需要一种方法来获取子表单查询并传递我需要传递的信息,然后在表单上调用更新。
Private Sub LoadSubform(unspscstring As String)
On Error GoTo Err_LoadSubform_Change
Dim dbs As Database
Dim strSQL As String
Dim strSelect As String
Dim strQueryName As String
Dim qryDef As QueryDef
Dim rst As Recordset
Dim prmOne As DAO.Parameter
Set dbs = CurrentDb
'then we'll open up the query:
Set qryDef = dbs.QueryDefs("spgetAttributeByUNSPSC")
'Now we'll assign values to the query using the parameters option:
'link your DAP.Parameters to the query
'Set prmOne = qryDef.Parameters!param_one
'prmOne = unspscstring
qryDef.Parameters(0) = unspscstring
'Now need to somehow trigger an update on the subform
'Close all objects
rst.Close
qryDef.Close
Set rst = Nothing
Set qryDef = Nothing
Bye_LoadSubform_Change:
Exit Sub
Err_LoadSubform_Change:
Beep: MsgBox Error$, 16, "Select Failed"
Resume Bye_LoadSubform_Change
End Sub