Results 1 to 5 of 5
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form Name that Opened Report? (A2k (9.0.3821) SR-1)

    When in the report, what is the code to retrieve the from name that opened the report?

    Thanks, John

  2. #2
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Form Name that Opened Report? (A2k (9.0.3821) SR-1)

    I don't believe that you have that functionality available.
    However, you could set up a global variable and prior to calling the report you could setup the form name in that.
    You then reference the global variable in the report.
    Pat <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  3. #3
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Form Name that Opened Report? (A2k (9.0.3821) SR-1)

    As Pat suggests you can use a global variable for this purpose. You will have to use a "wrapper" function to retrieve global variable's value. You would set value when report is opened from form. Example: In standard code module create Public variable and function:

    Option Compare Database
    Option Explicit

    Public gstrFormName As String

    Public Function GetFormName() As String
    GetFormName = gstrFormName
    End Function

    When opening report use code like this:

    Private Sub OpenRpt_btn_Click()

    Dim strRpt As String

    gstrFormName = Me.Name
    strRpt = "rptEmployees"
    DoCmd.OpenReport strRpt, acPreview

    End Sub

    To get name of form in report, call GetFormName function. To test this, add unbound textbox to report with following expression as ControlSource:

    ="Form Opened by: " & GetFormName()

    The textbox will display name of form that opened report.

    HTH

  4. #4
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Name that Opened Report? (A2k (9.0.3821) SR-1)

    Hi Mark

    Thanks, thats exactly what I was looking for.

    While I was researching Pat suggestion I came across the following:

    May be of interest to you and others, any comments on this approach?

    John

    Subject: Passing data ..form to form ..another way
    Date: 3/2/02 6:13 PM Eastern Standard Time
    From: Gken05
    Message-id: <20020302181348.11564.00001885@mb-dh.aol.com>

    Using public modules to create global variables has some limitations, depending on your needs and preferences. For instance, you cannot directly reference a global variable in a query. Yet there are times when you want to pass information the user put on a form to a query.You can create a function for each parameter to return the variable to the query. But this is adding complexity and maintenance headaches; adding a
    global variable to a public module, creating a new function if a query must have access to that variable, duplicating the process for each public variable you need. It can be a lot of extra work, especially if your variables will be used only 1 or 2 times in your entire application.

    Wouldn't it be great to be able to create a public variable on the fly, public variables that can be used in any form or in a query without extra coding or functions? That is, without having to maintain a list of public variables and without having to create a new function each time you wanted to pass the information in a public variable to a query?

    Scott Machado showed how in "Abstract Your Query Parameters" in the July 2001 issue of ACCESS VB- SQL

    Advisor magazine. Admittedly, his goal was to use data on a form in a query without having to reference the form. But his solution works as well when you want to pass data from form to form.

    In a nutshell, instead of the progammer maintaining a list of global variables in a public module, you let Access store your variables in a collection. You need 3 things: 1) a collection in which to store your public variables 2) a way to store information in the collection 3) a way to retrieve information from the collection

    This is it:

    1.Declaire the following in the declaration section of a public module:

    Public gloMyVariables As New Collection

    2. Use this public subroutine to set the value, ie, to store information in the collection

    Public Sub gloSetValue(ByVal vstrParamName As String, ByVal vvarValue As Variant)
    On Error Resume Next
    gloMyVariables.Remove vstrParamName
    gloMyVariables.Add vvarValue, vstrParamName
    End Sub

    3. and this public function to retrieve the value you stored

    Public Function gloGetValue(ByVal vstrParamName As String) As Variant
    On Error Resume Next
    gloGetValue = gloMyVariables(vstrParamName)
    End Function


    Of course, 'gloMyVariables" and routine and variable names are my preferences...

    Now, if you need to create a public variable to store information, you can do so on the fly. Say, the user has typed "Dusty" in a text box to answer a question about a pet's name. You can the add ...

    gloSetValue "userpetname", textboxname.value

    to the AfterUpdate event of the text box. Voila! A public variable has been created and you can close the form.To see the name of the pet in a text box on a 2nd another form, you could add the following to the open event of the 2nd form...

    textbox2ndform.value = gloGetvalue("userpetname")

    ... and "Dusty" will display in the text box on the 2nd form. You can also type gloGetvalue("userpetname") directly into the criteria of a query, which in this instance, would retrieve all records of pets named "Dusty".

    I've found this a simple and convienent way to create and retrieve public variables.

    Now, if one person out there really likes this, then I will sleep with a smile knowing I'd given something back when so many over the past 2 yrs have given me so much.

    Ken

  5. #5
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Form Name that Opened Report? (A2k (9.0.3821) SR-1)

    Well done by Scott Machado !!
    Well done by you for finding this !!
    Pat <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •