子窗口中的变量不会从父级接收值

时间:2009-04-16 16:04:59

标签: html vbscript parent-child

在html页面中,我创建了一个子窗口来执行一些过滤(选择打印机,以及在报告上打印哪些部分)。为了在子窗口上显示部件选择,我需要从父窗口调用GetParts函数并将记录集返回给子窗口。以下是一些有用的代码:

从子窗口 - >

Sub LoadParts(frmRptFilter)
Dim sql
Dim oParts
Set oParts = CreateObject("ADODB.Recordset")
oParts.Fields.Append "Part", adBSTR , 30
oParts.Open
oParts = window.opener.GetParts(oParts) 'Since oParts was passed as a parameter I did not believe this to be necessary, but when it didn't work as expected I tried returning it this way....didn't work either
'more code follows

在父窗口中 - >

Function GetParts(oParts)
Dim sql

sql = "SELECT Job.Part_Number FROM Job RIGHT JOIN Packlist_Detail ON Packlist_Detail.Job = Job.Job "_
    & "WHERE Packlist_Detail.Packlist LIKE '" & sPL & "'"

CloseRS(oRS)
oRS.Open sql, oConn, adOpenStatic, adLockReadOnly

oRS.MoveFirst

If Not (oRS.BOF AND oRS.EOF) Then
    Do while not oRS.EOF
        oParts.AddNew
        oParts("Part").Value = oRS(0)
        oParts.Update
        oRS.MoveNext
    Loop 
End If

'GetParts = oParts 'Since oParts was passed as a parameter I did not believe this to be necessary, but when it didn't work as expected I tried returning it this way....didn't work either
End Function

我为一个软件编写报告,要求我创建过滤器并报告包含水晶报表对象的html页面。我编写这些报告的软件限制了我在数据库连接方面可以做的事情。所以我必须这样做。

所以我验证了父窗口中的oParts是否正确填充。它做到了!我只是不能把它填满我的孩子的窗口。所以问题是,如何在子窗口中获取值?

2 个答案:

答案 0 :(得分:1)

试试这个 儿童窗口


Set oParts = window.opener.GetParts(oParts)

父窗口


Set GetParts = oParts

答案 1 :(得分:0)

Tester101:

尝试你所说的内容在父函数中出错: 对象需要'oParts'

看到这个我在那里定义了oParts记录集:

Set oParts = CreateObject("ADODB.Recordset")
oParts.Fields.Append "Part", adBSTR , 30
oParts.Open

现在一切都很棒。

所以这个问题的真正答案是Tester101的答案加上记录集的定义,即返回父级函数中的子窗口。

谢谢Tester101 !!!!