 |
| Access VBA Discuss using VBA for Access programming. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

January 17th, 2005, 04:30 PM
|
|
Authorized User
|
|
Join Date: Jan 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
OpenArgs to Sub Report
I am trying to use a form where the user can select the projects they have worked on for a project resume. I am using the OpenArgs property to pass the values form the form to the report. The problem is that the main report just has employee info on it and the sub report is where the project information is. I need to pass the OpenArgs from the main report to the sub report (the way the two reports are linked is through employeeID).
Public strFilter as String
Dim varItem As Variant
For Each varItem In Me!lstProjects.ItemsSelected
strFilter = strFilter & ",'" & _
Me![lstProjects].ItemData(varItem) & "'"
Next ' continue loop
If strFilter <> "" Then
strFilter = "[EPRproid] In (" & Mid(strFilter, 2) & ")"
Else
MsgBox "You did not select any project(s)."
lstProjects.SetFocus
Exit Sub
End If
DoCmd.OpenReport "rptCustomResume",
acPreview, , , ,OpenArgs:=strFilter
This is the code I am using to save the filter and pass it to the main report.
I am tried typing in the filter propety of the sub report:
me.rptResume.OpenArgs (me.parent.OpenArgs)
But it did not work, and I am thinking it is because the way the two reports are linked. Is there any other way of passing OpenArgs toa subrepor?
|
|

January 18th, 2005, 03:59 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
|
|
Try simply typing Me.Parent.OpenArgs in your filter property instead of me.rptResume.OpenArgs (me.parent.OpenArgs). You don't need to try and set the sub reports OpenArgs property. You already have the value you need in the parent reports OpenArgs property. Just use it. Your syntax (Me.Parent.OpenArgs) is the correct reference to that value. For example:
In Standard Module:
Sub OpenParentReport()
DoCmd.OpenReport "ParentReport", acViewPreview, OpenArgs:="Parent Opening Argument"
End Sub
In Parent reports Open Event:
Private Sub Report_Open(Cancel As Integer)
If Not IsNull(Me.OpenArgs) Then
Debug.Print Me.OpenArgs
End If
End Sub
In Sub reports Open Event which fires after the Parent reports open event:
Private Sub Report_Open(Cancel As Integer)
If Not IsNull(Me.Parent.OpenArgs) Then
Debug.Print Me.Parent.OpenArgs
End If
End Sub
Running this code will print:
Parent Opening Argument
Parent Opening Argument
So you should be able to refer to the Parent reports OpenArgs string anywhere you need it in the Sub report by simply using Me.Parent.OpenArgs.
HTH,
Bob
|
|

January 18th, 2005, 09:15 AM
|
|
Authorized User
|
|
Join Date: Jan 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for the reply. It still does not work. When I type me.parent.OpenArgs I am getting a parameter box that ask for me.parent.OpenArgs. Could it be becuase the relationship between the two reports is the employee and not the projects (which is what is in the openargs)? And when I try setting the filter of the sub report to the Public Variable (which could be decalred in the wrong place - it is decalred where the click_event of the button I have to open the report but at the top of the page as Public strFilter as string) and that just came up as strFilter = "". Thanks for the help.
|
|

January 18th, 2005, 11:36 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
|
|
The OpenArgs argument has nothing to do with the relationship between report and subreport. In fact, both the report and subreport could be unbound. The OpenArgs is merely an argument passed from the form to the report. To reference it from the subreport, you simply reference
Me.Parent.OpenArgs
For example
MsgBox "OpenArgs is " & Me.Parent.OpenArgs, vbInformation, "FYI"
Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
|
|

January 18th, 2005, 11:44 AM
|
|
Authorized User
|
|
Join Date: Jan 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Then if I type Me.Parent.OpenArgs in the filter or the sub report it should then filter the sub report to whatever projects where selected (if I am understanding that correctly). When I do this I get a parameter box. Is there anyway around this?
|
|

January 18th, 2005, 04:55 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
|
|
This works on my end. The OpenArgs string being sent to your Parent reports open event looks something like:
[EPRproid] In ('1','2')
This is a valid filter string so long as [EPRproid] is a text field.
Then, use the sub reports Activate event to set its Filter property:
Private Sub Report_Activate(Cancel As Integer)
If Not IsNull(Me.Parent.OpenArgs) Then
Me.Filter = Me.Parent.OpenArgs
Me.FilterOn = True
End If
End Sub
If you continue to get a parameter input box, check and be sure that [EPRproid] is a correctly spelled field name in your table.
HTH,
Bob
|
|

January 18th, 2005, 05:30 PM
|
|
Authorized User
|
|
Join Date: Jan 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The error messages are gone but no projects show up. Here is all my code maybe it is something in here: (strFilter is a Public Vairable declared elsewhere in a module)
From the Form where the list boc and employee selection is made:
Private Sub cmdReport_Click()
Dim varItem As Variant
strFilter = ""
strEmp = ""
For Each varItem In Me!lstProjects.ItemsSelected
strFilter = strFilter & ",'" & _
Me![lstProjects].ItemData(varItem) & "'"
Next
If strFilter <> "" Then
strFilter = "[EPRproid] In (" & Mid(strFilter, 2) & ")"
Else
MsgBox "You did not select any project(s)."
lstProjects.SetFocus
Exit Sub
End If
'Set Employee Variable
strEmp = "[EMPid] In (" & (CStr(EMPid)) & ")"
'Opens Report and displays only employee selected on the form and brings over the projects through OpenArgs
DoCmd.OpenReport "rptCustomResume", acViewPreview, , strEmp, , OpenArgs:=strFilter
'Clears List Box
For i = 0 To Me.lstProjects.ListCount - 1
Me.lstProjects.Selected(i) = False
Next i
End Sub
Open Event of rptCustomResume: (Parent Report)
Private Sub Report_Open(Cancel As Integer)
If Not IsNull(Me.OpenArgs) Then
Debug.Print Me.OpenArgs
End If
End Sub
Activate Event of Sub Report (rptCustomResumeProjectsSub)
Private Sub Report_Activate(Cancel As Integer)
If Not IsNull(Me.Parent.OpenArgs) Then
Me.Filter = Me.Parent.OpenArgs
Me.FilterOn = True
End If
End Sub
Open Event of Sub Report (rptCustomResumeProjectsSub)
Private Sub Report_Open(Cancel As Integer)
If Not IsNull(Reports![rptCustomResume].OpenArgs) Then
Debug.Print Reports![rptCustomResume].OpenArgs
End If
End Sub
Hope this helps... thanks again for all the help
|
|

January 18th, 2005, 05:34 PM
|
|
Authorized User
|
|
Join Date: Jan 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I have an input mask in the table for PROid which is the Primary key of table Projects and is linked to EPRproid (foreign key) in the EmployeeProjects Table. Would the input mask have an affect on anything?
|
|

January 18th, 2005, 05:46 PM
|
|
Authorized User
|
|
Join Date: Jan 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
For the Post at 01/18/2005 : 9:30:34 PM
The subreport which shows the projects assoicated with that person there is nothing showing.
Just wanted to clarify that.
|
|

January 18th, 2005, 05:48 PM
|
|
Authorized User
|
|
Join Date: Jan 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
This is the code in the Opoen Event of the Sub Report not what is above (sorry about that).
Private Sub Report_Open(Cancel As Integer)
If Not IsNull(Me.Parent.OpenArgs) Then
Debug.Print Me.Parent.OpenArgs
End If
End Sub
|
|
 |