473,587 Members | 2,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Having trouble with filter on multi-select listbox

31 New Member
Hi All,

I am having trouble filtering a report with a multiselect list box. The report is generated, but it is not filtered based on the selections of the list box:

lstVehID
Multi Select Simple
Row Source Type Table/Query
Row Source SELECT qryVehicle.Vehi cle, qryVehicle.[RBL Status] FROM qryVehicle ORDER BY qryVehicle.Vehi cle;


Users enter their information into form:
frmCustomers

A command button (cmdPOHCReport) opens the report:
rptPOHC
which is run off query:
qryPOHC_Custome r

I am using Allen Browne's VBA code to filter the query with the selections from the list box.

In an Access 2003 version of this database I was able to set strDoc = "Name of Report", however now

If I set
strDoc = "rptPOHC"
I get a message box asking me for [Vehicle]

If I set
strDoc = "qryPOHC_Custom er"
I get "Error 2467 - The expression you entered refers to an object that is closed or does not exist"

I have attached a copy of the DB. Any help would be much appreciated


Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdPOHCReport_Click()
  2.  
  3. On Error GoTo Err_Handler
  4.     'Purpose:  Open the report filtered to the items selected in the list box.
  5.     'Author:   Allen J Browne, 2004.   http://allenbrowne.com
  6.     Dim varItem As Variant      'Selected items
  7.     Dim strWhere As String      'String to use as WhereCondition
  8.     Dim strDescrip As String    'Description of WhereCondition
  9.     Dim lngLen As Long          'Length of string
  10.     Dim strDelim As String      'Delimiter for this field type.
  11.     Dim strDoc As String        'Name of report to open.
  12.  
  13.     strDelim = """"            'Delimiter appropriate to field type. See note 1."
  14.     strDoc = "qryPOHC_Customer"
  15.  
  16.     'Loop through the ItemsSelected in the list box.
  17.     With Me.lstVehID
  18.         For Each varItem In .ItemsSelected
  19.             If Not IsNull(varItem) Then
  20.                 'Build up the filter from the bound column (hidden).
  21.                 strWhere = strWhere & strDelim & .ItemData(varItem) & strDelim & ","
  22.                 'Build up the description from the text in the visible column. See note 2.
  23.                 strDescrip = strDescrip & """" & .Column(0, varItem) & """, "
  24.             End If
  25.         Next
  26.     End With
  27.  
  28.     'Remove trailing comma. Add field name, IN operator, and brackets.
  29.     lngLen = Len(strWhere) - 1
  30.     If lngLen > 0 Then
  31.         strWhere = "[Vehicle] IN (" & Left$(strWhere, lngLen) & ")"
  32.         lngLen = Len(strDescrip) - 2
  33.         If lngLen > 0 Then
  34.             strDescrip = "Categories: " & Left$(strDescrip, lngLen)
  35.         End If
  36.     End If
  37.  
  38.     'Report will not filter if open, so close it. For Access 97, see note 3.
  39.     If CurrentProject.AllReports(strDoc).IsLoaded Then
  40.         DoCmd.Close acReport, strDoc
  41.     End If
  42.  
  43.     'Omit the last argument for Access 2000 and earlier. See note 4.
  44.     DoCmd.OpenReport strDoc, acViewPreview, WhereCondition:=strWhere, OpenArgs:=strDescrip
  45.  
  46. Exit_Handler:
  47.     Exit Sub
  48.  
  49. Err_Handler:
  50.     If Err.Number <> 2501 Then  'Ignore "Report cancelled" error.
  51.         MsgBox "Error " & Err.Number & " - " & Err.Description, , "PrevLim_Click"
  52.     End If
  53.     Resume Exit_Handler
Attached Files
File Type: zip MultiSelect.zip (955.6 KB, 102 views)
Jun 15 '12 #1
1 1854
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Whats the query or table that the report is based on? That information is missing from your question, and sorry, I wont start downloading attachments from unknown sources. You will have to provide the information in your question.
Jun 18 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2580
by: Anand | last post by:
Hi i am having trouble adding a recordset into the access database, the code seems to be working fine it passs and parses through all variables just fine without showing any errors and also when i access the recordset it displays the results, what the real issue is that the entry is not made into the database even though i use the Update...
2
2518
by: ed | last post by:
i'm having trouble with a form. I want to be able to type in the address of the form with the data for the form items in the URL (ie: http://somesite.com/formpage.html?field1=data1&field2=data2). It saves the data if I type it in manually to an html file. But it won't do that if I use the URL notation above. How do I get it to do this. ...
1
1791
by: Lauren Wilson | last post by:
I'm having trouble with the Access VBA help on my installation of A2K with Dev tools. Every time I try to retrieve help for items listed in the Object Browser (and SOME other items as well), Access tells me that the "feature is broken" and prompts me to repair it. When I do so, it goes through the motions but does NOT repair the help files....
2
4536
by: Jozef | last post by:
Hello, I am trying to put together a module and open a workspace on a database that has a simple password (using Access XP). This is the lin that I'm having trouble with; Set wrk = CreateWorkspace("TestWrkspc", "Admin", conDbPwd) conDBPwd is a variable that contains the password. There is no independant workgroup file, just the...
0
1527
by: Jozef | last post by:
Hello, I'm having trouble with the download links on my web server. The error I'm getting is; CGI Timeout The specified CGI application exceeded the allowed time for processing. The server has deleted the process. It's a fresh Windows 2000 server install, but I also installed the ASP.net
1
1616
by: Jozef | last post by:
Hello. I'm having trouble creating a blank solution (and ASP.net web application) from my laptop. I own the server (in fact it's sitting right next to me) and have added the URL to the trusted sites on my laptop. Here are the details; This is what I'm selecting from the start page.... >Add New Blank Solution >Visual Basic Projects,
2
1748
by: Jake Barnes | last post by:
I've read over the documentation for these effects: http://wiki.script.aculo.us/scriptaculous/show/CombinationEffectsDemo I want to include them on my page. I tried attaching using onload, but that didn't work. In fact, I can not get them to work even as inline commands. I click on the DIV with the id of newMailList, I only get an errror....
3
5735
by: Michael | last post by:
Hi all, I'm having trouble PInvoking a TCHAR within a struct. I'll paste the specific struct's API definition below. I've tried so many numerous variations. The main Win32 error I get is 0x3f0 / 515L which amounts to ERROR_NO_TOKEN. Every single instance of this in the past was due to mistakes I made while within PInvoked structs. Is...
5
3489
by: tkondal | last post by:
Hi all. I just started looking at Python's ctypes lib and I am having trouble using it for a function. For starters, here's my Python code: from ctypes import*; myStringDLL= cdll.LoadLibrary("myStringDLL.dll");
2
2011
by: Stu | last post by:
Hi guys, I've been having trouble getting the clock function to work portably, please could I get some thoughts? <Possibly OT comments> It works fine on my laptop (under WinXP) and on my office computer (under Linux), but I have to write some code for the system simulator for the Cell BE processor (the thing inside the PS3), which is...
0
7918
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8206
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5713
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5392
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2353
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.