PC Review


Reply
Thread Tools Rate Thread

More Problems with List Box

 
 
richard
Guest
Posts: n/a
 
      7th Feb 2008
Hi

Having some problems running a report with a list box selection. Below is
the code I am using.
The code should create a criteria (in the field Seperator) to run a report
based upon a query, however this is not happening. If I enter the criteria
directly into the query and then run the query it works fine, so it would
appear the criteria is not being passed to the query.
The problem is the report runs and shows all records from the table
regardless of the selection in the list box

Private Sub cmdRunReport_Click()

Dim varItem As Variant
Dim strCriteria As String
Dim strAssistFMJobs As String
Dim stDocName As String
Dim ctrl As Control

Set ctrl = Me.lstAssistFMJobs



For Each varItem In ctrl.ItemsSelected
strAssistFMJobs = strAssistFMJobs & "," & ctrl.ItemData(varItem)
Next varItem

strAssistFMJobs = Mid(strAssistFMJobs, 2)
strCriteria = "Seperator In(" & strAssistFMJobs & ")"


If Len(strAssistFMJobs) = 0 Then
MsgBox "You did not select anything from the list", vbExclamation,
"Nothing to find!"
Exit Sub
End If

stDocName = "Data Sheet for Clients"
DoCmd.OpenReport stDocName, acViewPreview, strCriteria

End Sub

Thanks

Richard
 
Reply With Quote
 
 
 
 
Rick Brandt
Guest
Posts: n/a
 
      7th Feb 2008
richard wrote:
> Having some problems running a report with a list box selection.
> Below is the code I am using.
> The code should create a criteria (in the field Seperator) to run a
> report based upon a query, however this is not happening. If I enter
> the criteria directly into the query and then run the query it works
> fine, so it would appear the criteria is not being passed to the
> query.

[snip]

> stDocName = "Data Sheet for Clients"
> DoCmd.OpenReport stDocName, acViewPreview, strCriteria


You are putting your criteria in the Filter argument. It belongs in the Where
argument. Just add one more comma...

DoCmd.OpenReport stDocName, acViewPreview,, strCriteria

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com


 
Reply With Quote
 
 
 
 
Pat Hartman
Guest
Posts: n/a
 
      7th Feb 2008
Seperator is spelled incorrectly. The correct spelling is Separator.
"richard" <(E-Mail Removed)> wrote in message
news:1B312683-C375-48D8-8600-(E-Mail Removed)...
> Hi
>
> Having some problems running a report with a list box selection. Below is
> the code I am using.
> The code should create a criteria (in the field Seperator) to run a report
> based upon a query, however this is not happening. If I enter the criteria
> directly into the query and then run the query it works fine, so it would
> appear the criteria is not being passed to the query.
> The problem is the report runs and shows all records from the table
> regardless of the selection in the list box
>
> Private Sub cmdRunReport_Click()
>
> Dim varItem As Variant
> Dim strCriteria As String
> Dim strAssistFMJobs As String
> Dim stDocName As String
> Dim ctrl As Control
>
> Set ctrl = Me.lstAssistFMJobs
>
>
>
> For Each varItem In ctrl.ItemsSelected
> strAssistFMJobs = strAssistFMJobs & "," & ctrl.ItemData(varItem)
> Next varItem
>
> strAssistFMJobs = Mid(strAssistFMJobs, 2)
> strCriteria = "Seperator In(" & strAssistFMJobs & ")"
>
>
> If Len(strAssistFMJobs) = 0 Then
> MsgBox "You did not select anything from the list", vbExclamation,
> "Nothing to find!"
> Exit Sub
> End If
>
> stDocName = "Data Sheet for Clients"
> DoCmd.OpenReport stDocName, acViewPreview, strCriteria
>
> End Sub
>
> Thanks
>
> Richard



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
More and More page loading issues: usual IE woes and more =?Utf-8?B?QSBHdW5zbGluZ2Vy?= Windows XP Internet Explorer 2 9th Mar 2006 11:07 PM
Temp Files - More & More & More of them??? Stew Spyware Discussion 6 28th Sep 2005 05:13 PM
How to apply 2 or more text box filters to 1 list box on form =?Utf-8?B?ZGFuaWVscnQ5?= Microsoft Access Forms 2 6th Sep 2005 09:34 AM
Error Message: Windows cannot find 'box,box,box,box,box' =?Utf-8?B?Ym91Y2hhcmRwaWU=?= Windows XP Help 2 25th Jul 2005 08:47 PM
Multi-Selected Items from one List Box to other empty List Box and text box Sumit Microsoft Access Form Coding 3 15th Jul 2003 09:11 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:14 AM.