473,732 Members | 2,201 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to String IDs from Multi-Select List Box with Date Range andOther Criteria

If able, can someone please help make a Where clause that strings
together IDs in a multi-select listbox AND includes a date range.

I wasn’t thinking when I used the code below that strings together the
IDs of Clients from a multi-select listbox in an unbound text field,
txtCriteria, on a form that is used to pick different reports. It
appears that I now have so many clients that I’ve reached the 255
character limit in the txtCriteria field, thus leaving some clients
out of the report filter—so I need to use the Open Args instead?

I’m trying to piece together info from Allen Brown, from his pages
http://allenbrowne.com/ser-62.html, http://allenbrowne.com/ser-50.html,
and http://www.allenbrowne.com/casu-08.html.

My initial, adapted code worked great, accept for the fact that
clients at the end of the list weren’t being included in the where.
These are the fields in the report selection form:

lstChosen = multi-select listbox with Client IDs and names in columns
txtCriteria = temp textbox to string the selected Clients – this needs
to be omitted an just put into a where
optNames = option group to toggle between client full and abbreviated
names for HIPAA privacy reasons

********INITIAL CODE********

Private Sub cmdViewDailySum mary_Click()

On Error GoTo Err_cmdViewDail ySummary_Click

Dim strDoc As String
Dim varItem As Variant

Dim strField As String
Dim strWhere As String
Const conDateFormat = "\#mm\/dd\/yyyy\#"
strField = "txtDatePar t"

Me.txtCriteria = ""

For Each varItem In lstChosen.Items Selected
Me.txtCriteria = Me.txtCriteria & "," &
lstChosen.ItemD ata(varItem)
Next varItem

Me.txtCriteria = Mid(Me.txtCrite ria, 2)

If Me.optNames = 1 Then
strDoc = "rptSummaryToda yAscFull"
If IsNull(Me.txtSt artDate) Then
If Not IsNull(Me.txtEn dDate) Then
strWhere = strField & " <= " & Format(Me.txtEn dDate,
conDateFormat)
End If
Else
If IsNull(Me.txtEn dDate) Then
strWhere = strField & " >= " & Format(Me.txtSt artDate,
conDateFormat)
Else
strWhere = strField & " Between " &
Format(Me.txtSt artDate, conDateFormat) _
& " And " & Format(Me.txtEn dDate, conDateFormat)
End If
End If

DoCmd.OpenRepor t strDoc, acPreview, , strWhere
ElseIf Me.optNames = 2 Then
strDoc = "rptSummaryToda yAsc"

If IsNull(Me.txtSt artDate) Then
If Not IsNull(Me.txtEn dDate) Then
strWhere = strField & " <= " & Format(Me.txtEn dDate,
conDateFormat)
End If
Else
If IsNull(Me.txtEn dDate) Then
strWhere = strField & " >= " & Format(Me.txtSt artDate,
conDateFormat)
Else
strWhere = strField & " Between " &
Format(Me.txtSt artDate, conDateFormat) _
& " And " & Format(Me.txtEn dDate, conDateFormat)
End If
End If
DoCmd.OpenRepor t strDoc, acPreview, , strWhere
End If

Exit_cmdViewDai lySummary_Click :
Exit Sub

Err_cmdViewDail ySummary_Click:
If Err.Number = 2501 Then
Resume Next
Else
MsgBox Err.Description
Resume Exit_cmdViewDai lySummary_Click
End If

End Sub

********ATTEMPT TO REVISE********

Private Sub cmdViewDailySum mary_Click()

On Error GoTo Err_cmdViewDail ySummary_Click

On Error GoTo Err_Handler
Dim varItem As Variant
Dim strWhere As String
Dim strDescrip As String
Dim lngLen As Long
Dim strDelim As String
Dim strDoc As String

Dim strField As String
Const conDateFormat = "\#mm\/dd\/yyyy\#"
strField = "txtDatePar t"

With Me.lstChosen
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
strWhere = strWhere & strDelim & .ItemData(varIt em) &
strDelim & ","
strDescrip = strDescrip & """" & .Column(1, varItem) &
""", "
End If
Next
End With

lngLen = Len(strWhere) - 1
If lngLen 0 Then
strWhere = "[ClientID] IN (" & Left$(strWhere, lngLen) & ")"
lngLen = Len(strDescrip) - 2
If lngLen 0 Then
strDescrip = "Clients: " & Left$(strDescri p, lngLen)
End If
End If

‘ This is where the above where statement containing Clients need to
now contain the date range.

If Me.optNames = 1 Then
strDoc = "rptSummaryFull "
DoCmd.OpenRepor t strDoc, acViewPreview, WhereCondition: =strWhere,
OpenArgs:=strDe scrip

ElseIf Me.optNames = 2 Then
strDoc = " rptSummaryShort "
DoCmd.OpenRepor t strDoc, acViewPreview, WhereCondition: =strWhere,
OpenArgs:=strDe scrip

End If

Exit_Handler:
Exit Sub

Err_Handler:
If Err.Number <2501 Then
MsgBox "Error " & Err.Number & " - " & Err.Description , ,
"cmdViewDailySu mmary_Click"
End If
Resume Exit_Handler
So, ultimately, a string can be passed into one or more textboxes in
the proper report in this format: =[rptSummary].[OpenArgs].

Without this group and sites like Allen, I’d be even more lost.
Thanks for any and all help.
Aug 20 '08 #1
3 3265
Hi,
there's no reason to be afraid.

Instead of putting the concatenated list into your textbox, just put
them to a string variable.

See the changes I've made in the Initial code as an example. No need
for openargs.

6a************* **@gmail.com wrote in
news:20******** *************** ***********@t54 g2000hsg.google groups.co
m:
If able, can someone please help make a Where clause that strings
together IDs in a multi-select listbox AND includes a date range.

I wasn’t thinking when I used the code below that strings together
the IDs of Clients from a multi-select listbox in an unbound text
field, txtCriteria, on a form that is used to pick different
reports. It appears that I now have so many clients that I’ve
reached the 255 character limit in the txtCriteria field, thus
leaving some clients out of the report filter—so I need to use the
Open Args instead?

I’m trying to piece together info from Allen Brown, from his pages
http://allenbrowne.com/ser-62.html,
http://allenbrowne.com/ser-50.html, and
http://www.allenbrowne.com/casu-08.html.

My initial, adapted code worked great, accept for the fact that
clients at the end of the list weren’t being included in the
where. These are the fields in the report selection form:

lstChosen = multi-select listbox with Client IDs and names in
columns txtCriteria = temp textbox to string the selected Clients
– this needs to be omitted an just put into a where
optNames = option group to toggle between client full and
abbreviated names for HIPAA privacy reasons

********INITIAL CODE********

Private Sub cmdViewDailySum mary_Click()

On Error GoTo Err_cmdViewDail ySummary_Click

Dim strDoc As String
Dim varItem As Variant

Dim strField As String
Dim strWhere As String
Const conDateFormat = "\#mm\/dd\/yyyy\#"
strField = "txtDatePar t"

Me.txtCriteria = "" ' delete this
Dim strClientList as string
Dim strAnd as string
>
For Each varItem In lstChosen.Items Selected
' some changes here.
strClientList = strClientList & "," &
lstChosen.ItemD ata(varItem)
Next varItem

strClientList = Mid(strClientLi st, 2)
if len(strclientLi st) 0 then
strClientlist "ClientID IN (" & strClientID & ")"
end if

' I've split the report selection code from the date filter
' because the date filter was duplicated.

If Me.optNames = 1 Then
strDoc = "rptSummaryToda yAscFull"
ElseIf Me.optNames = 2 Then
strDoc = "rptSummaryToda yAsc"
End If

If IsNull(Me.txtSt artDate) Then
If Not IsNull(Me.txtEn dDate) Then
strWhere = strField & " <= " _
& Format(Me.txtEn dDate, conDateFormat)
End If
Else
If IsNull(Me.txtEn dDate) Then
strWhere = strField & " >= " _
& Format(Me.txtSt artDate, conDateFormat)
Else
strWhere = strField & " Between " &
Format(Me.txtSt artDate, conDateFormat) _
& " And " & Format(Me.txtEn dDate, conDateFormat)
End If
End IF

' The big change is here.
' We test if the date filter is empty and the client filter is empty.
' If neither is empty, we need an And between them, othrewise we need
nothing.
If len(strWhere) 0 AND len(strClientLi st) >0 then
strAnd = " AND "
end if

strwhere = strwhere & strAnd & strClientList
DoCmd.OpenRepor t strDoc, acPreview, , strWhere
Exit_cmdViewDai lySummary_Click :
Exit Sub

Err_cmdViewDail ySummary_Click:
If Err.Number = 2501 Then
Resume Next
Else
MsgBox Err.Description
Resume Exit_cmdViewDai lySummary_Click
End If

End Sub

So, ultimately, a string can be passed into one or more textboxes
in the proper report in this format: =[rptSummary].[OpenArgs].

Without this group and sites like Allen, I’d be even more lost.
Thanks for any and all help.


--
Bob Quintal

PA is y I've altered my email address.
** Posted from http://www.teranews.com **
Aug 20 '08 #2
It sounds like you want to get a subset of data for the recordsource of
a report where this subset of data is based on a list of clients.

If this is the case then it sounds like you are concatenating this list
of clients as one string to be used as criteria. If this is the case
then what you want to do is to copy the list of clients to a temp table
and use something like the following for the recordsource of your
reports

rpt.RecordSourc e = "Select distinct * from someTbl Where ClientName In
(Select * From tmpClient)"

using sql can shrink your coding from hundreds of lines to 1 or 2 lines
of code.
Rich

*** Sent via Developersdex http://www.developersdex.com ***
Aug 20 '08 #3
THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU
Aug 21 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1911
by: lkrubner | last post by:
Last year I asked a bunch of questions about character encoding on this newsgroup. All the answers came down to using ord() in creative ways to try to make guesses about multi-byte characters. I was a little amazed at this and wondered if I'd somehow misunderstood the situation. I'm pleased to find that Joel Spolsky shared my amazement and offered some criticism of PHP on these grounds: "When I discovered that the popular web development...
1
8436
by: JVarsoke | last post by:
I'm trying to use pgpenvelope and I keep getting the message: Can't locate loadable object for module String::Approx in @INC (@INC contains: /usr/lib/perl5/5.8.0/i586-linux-thread-multi . . . But hostname:/usr/lib/perl5/site_perl/5.8.0/i586-linux-thread-multi/String # ls -al total 32 drwxr-xr-x 2 root root 4096 2004-02-28 01:37 .
12
1977
by: joe martin | last post by:
In recent discussions relating to what to use for a new project which integrated the work of two, previously seperate, teams we got to the subject of our respective string implementations. One team rolled their own strings while the other used the std::string. Reasons for using the home-grown strings(and vectors) were mainly refcounting and portabillity, but I thought that these days almost all STL implementations used refcounted strings...
1
4282
by: googlegrouper | last post by:
I'm using a Unicode sql script imported using OSQL. One of the values we are attempting to insert is a Registry Multi-String value by passing a string to a stored procedure. These Multi-String values appear to be delimited by a Hex 06 (^F) character. When I import this character, embedded in a string preceeded by an N, i.e N'somethingsomething2something3' I end up with TWO of this character in the db. I get :
1
2034
by: Mike L | last post by:
This is for a Win form. I am able to send a string to my multi line text box, but I want the string to have hard returns in it. Here is my code for the string. string s = string.Format(Cell1 + " - " + Cell2 + " - " + Cell3 + " - " + Cell4);
1
1888
by: Arjen | last post by:
Hi, I want to have a multi string array, but I don't know the syntax. private string myArray = new string { {"1", "a", " ", " "}, {"2", "b", " ", " "}, {"3", "c", " ", " "} }
5
1704
by: Chris Mullins | last post by:
I've spent some time recently looking into optimizing some memory usage in our products. Much of this was doing through the use of string Interning. I spent the time and checked numbers in both x86 and x64, and have published the results here: http://www.coversant.com/dotnetnuke/Default.aspx?tabid=88&EntryID=24 The benefits for our SoapBox suite of products are pretty compelling, memory wise. Before I roll the changes into our...
5
5367
by: pnsreee | last post by:
Hi all, im using following perl code to check integer. use Tie::CheckVariables Tie::CheckVariables->on_error(sub{print "ERROR!"}); tie my $scalar,'Tie::CheckVariables','integer'; #$scalar = 88; $scalar = 'test';
10
4864
by: v4vijayakumar | last post by:
1. why the following program is not working as expected? #include <iostream> using namespace std; int main() { string t("test"); wcout << (wchar_t *) t.c_str() << endl; wcout << t.c_str() << endl;
0
1352
by: Rik Moed | last post by:
Hi all, I encounter a problem with a library method that should create a multi dimensional string array. Below is the method: -------------------------------------------------------------------------------- public class StringArrayLibrary { public void Create(ref string names)
0
8946
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9447
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9307
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9235
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9181
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6031
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.