Results 1 to 3 of 3
  1. #1
    apagan is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    3

    Using TempVar values from ListBox to run Report Query

    I am using a ListBox to capture multiple column values. I use SetTempVar to hold the desired values and


    Open a Report query that depends on these values. I was expecting that the report would have access to the TempVars values,
    which are used in the WHERE Clause, but it doesn't look like the report has access to them.

    I am using these 2 lines in VB. The first one to confirm that the values were set, and they are. And, the 2nd to
    open the report. What am I doing wrong?

    1. MsgBox "This was selected: " & Me.Team.Column(0) & " " & TempVars!teamID & " " & TempVars!yearID

    2. DoCmd.OpenReport "Teams Record & Roster", acViewReport, , , , "TempVars!teamID, TempVars!yearID"

    Thanks in Advance.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,522
    you cant use listbox.column(N) in a query.
    you must use the BOUND COLUMN so the listbox gets the value, then just use forms!myForm!listbox in the query.
    but you cannot use multivalue, instead use another table to collect items from the listbox,(via dbl-click) then join the Picked items to the main data :

    Attached is the table I use. When the user dbl-clicks a person, the dbl-click event runs an append query to put it in the tPicked table. lstPicked.requery must run too to refresh the screen
    lstAvail.rowsource = qsPersons
    lstPicked.rowsource = qsPicked
    Code:
    private sub lstAvail_doubleclick()
        docmd.setwarnings false
        docmd.openquery "qaAddPickedPerson"
        lstPicked.requery
    end sub
    Click image for larger version. 

Name:	Charge fees.jpg 
Views:	10 
Size:	24.5 KB 
ID:	37306

  3. #3
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,002
    You don't need the tempvars in this instance if they are simply to use in a where clause. However you need to build your where clause as a string, something like

    Code:
    Dim sWhere as String
    
    sWhere  = "[TeamID] =" & TempVars!teamID & " AND [YearID] =  " & TempVars!yearID
    
    DoCmd.OpenReport "Teams Record & Roster", acViewReport, , sWhere
    This assumes your ID fields are numbers. If not escape them with ' ' in the string concatenation.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

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

Similar Threads

  1. Replies: 4
    Last Post: 11-21-2018, 04:06 PM
  2. tempvar and query criteria
    By Jen0dorf in forum Access
    Replies: 2
    Last Post: 07-23-2016, 10:43 AM
  3. Syntax for TempVar to filter report (Web disastabase)
    By TheSnapperWhisperer in forum Access
    Replies: 0
    Last Post: 12-02-2015, 02:17 PM
  4. Replies: 7
    Last Post: 04-29-2015, 10:57 AM
  5. Replies: 5
    Last Post: 11-16-2014, 03:50 PM

Tags for this Thread

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