From: Douglas J. Steele on 28 May 2010 08:58 What I typically do is build a string to hold everything. To make it easier, I'll use something like: Dim strOpenArgs As String strOpenArgs = "heading=" & strHeading & ";" & _ "subheading=" & strSubHeading DoCmd.OpenReport "NameOfReport", OpenArgs:=strOpenArgs Then, in the Open event of the report, I parse that string: Private Sub Report_Open(Cancel As Integer) Dim lngLoop As Long Dim strHeading As String Dim strSubheading As String Dim varArg As Variant Dim varArgs As Variant strHeading = "default value" strSubheading = "default value" If Len(Me.OpenArgs & vbNullString) > 0 Then ' Break the OpenArgs argument into the various parameters ' by splitting on the semi-colons. varArgs = Split(Me.OpenArgs, ";") For lngLoop = LBound(varArgs) To UBound(varArgs) ' For each argument, split on the equal sign. ' The name of the argument will be varArg(0), ' the value of the argument will be varArg(1) varArg = Split(varArgs(lngLoop), "=") If UBound(varArg) > 0 Then Select Case LCase(varArg(0)) Case "heading" strHeading = varArg(1) Case "subheading" strSubheading = varArg(1) Case Else MsgBox "You passed " & varArg(0) & vbCrLf & _ "Sorry: I don't know what to do with " & varArg(0) & "!" End Select End If Next lngLoop End If ' Check to see whether or not you have values for strHeading ' and strSubheading, and process accordingly. End Sub -- Doug Steele, Microsoft Access MVP http://www.AccessMVP.com/DJSteele Co-author: Access 2010 Solutions, published by Wiley (no e-mails, please!) "Song" <song.usa(a)gmail.com> wrote in message news:0ae6acc4-818b-4136-a3c7-c481fbe988a6(a)32g2000prq.googlegroups.com... > > Got it. If I have 2 items to pass, say heading and subheading, is any > efficient way to do it? >> >> Open the report along the lines of: >> >> DoCmd.OpenReport "NameOfReport", OpenArgs:=Me.Name >> >> Then, in the Open event of the report, check the value passed: >> >> Private Sub Report_Open(Cancel As Integer) >> >> Select Case Nz(Me.OpenArgs, vbNullString) >> Case "NameOfForm1" >> ' do what you want if it was called from Form1 >> Case "NameOfForm2" >> ' do what you want if it was called from Form2 >> Case Else >> ' do you want to do anything if it was called from somewhere else? >> End Select >> >> End Sub >
First
|
Prev
|
Pages: 1 2 Prev: Karol Łusiaczyk Next: How to construct a hierarchy from a list? (Access 2003) |