views:

491

answers:

2

From within an html page, I create a child window to perform some filtering (choosing the printer, and what parts to print on the report). In order to show the part selection on the child window, I need to call a GetParts function from the parent window and return the recordset to the child. Here's some code to help:

From the child window->

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

In the Parent window ->

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

I write reports for a software that requires me to create filter and report html pages that contain the crystal report object. The software for which I write these reports limits what I can do in terms of db connections amongst other things. So I have to things this way.

So I verified that oParts in the parent window gets filled properly. Which it does! I just can not get it filled in my child window. So the question is, How do I get a value back in the child window?

+1  A: 

Try This
Child Window


Set oParts = window.opener.GetParts(oParts)

Parent Window


Set GetParts = oParts
Tester101
A: 

Tester101:

Trying what you said gave an error in the parent function: Object required 'oParts'

Seeing this I defined the oParts recordset in there:

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

And now everything works awesome.

So the real answer to this question is Tester101's answer plus definition of the recordset that is to return to the child window in the parent's function.

Thanks Tester101!!!!

Dewm Solo
I don't understand why your original code didn't work, unless there is something that stops objects from being passed by reference between windows? Glad I could help anyway.
Tester101
If you care to try it I would be interested to know if running your original code, but changing the function definition to Function GetParts(ByRef oParts) works.
Tester101
I will try it later and let you know what happens.
Dewm Solo