Results 1 to 5 of 5
  1. #1
    f15e is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2016
    Posts
    71

    Reference Report from a Form using a variable

    When I call a sub procedure located in my Report's from my main form using hard coded values, I am able to call a report with no problem.
    This works:
    DoCmd.OpenReport Bridge_Rpt, acViewReport, , , acHidden
    Me.Bridge_Rpt.Report.Min_Max_Val("Bridge_Tbl", "ST")

    But what I really need is to be able to use string variables b/c there are different reports based on what the user selects. I've tried the following with no luck:
    DoCmd.OpenReport selected_rpt, acViewReport, , , acHidden
    Me.[selected_rpt].Report.Min_Max_Val(Tbl_Name, Selected_UoM)

    selected_rpt = name of report user selected
    Tbl_Name = table associated with the report


    Selected_UoM = the unit of measure the user selected

    I am getting the following error:
    Microsoft Access cannot find the field '|1'referred to in your expression

    What is the correct way to call a sub procedure in a report without having to hard code it? By the way, as a test, I placed a MsgBox "Hello" as the 1st line in the Report sub procedure Min_Max_Val but it doesn't get past the Call to the report procedure. I never get the message box popup with Hello.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    i always let the query handle this, so there's no programming.
    The query gets the MIN_mAX_vAL, so the report field shows it.
    Dont make more work by writing code.

  3. #3
    f15e is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2016
    Posts
    71
    I get what you're saying but I still need to know how to use a variable (name of selected report) in my call to a report outside of my main form.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,899
    Not understanding the code. You open a report named Bridge_rpt? Then you reference a subform/subreport container control named Bridge_rpt containing a report object? That control is on form? What is the object in the container?

    Examples of using string variable to reference objects:

    Reports(selected_rpt)

    strLabel = Forms(Me.Name).Controls("lblGrad" & i).Caption

    Calling a procedure in another object: Call Forms("SampleManagement").SelectRecord

    Calling a procedure in a subform referencing through the container: Call Me.ctr1.Form.SaveData
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    f15e is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2016
    Posts
    71
    I got it working. Thanks for all your help!!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. DLookup reference column according to variable
    By hockeyman9474 in forum Programming
    Replies: 7
    Last Post: 05-26-2017, 11:55 PM
  2. Replies: 4
    Last Post: 01-19-2016, 07:50 PM
  3. Variable to reference a spreadsheet from Access
    By lawdy in forum Programming
    Replies: 9
    Last Post: 03-03-2015, 11:31 AM
  4. Variable within form control reference
    By Tyork in forum Programming
    Replies: 2
    Last Post: 10-13-2010, 09:55 AM
  5. Replies: 2
    Last Post: 05-09-2010, 04:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums