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

Home Posts Topics Members FAQ

multi-select list box

MSD
I am running a report that uses a query as its record source and opens a
form collecting beginning and ending item numbers to feed to the query. This
works, but now I'm trying to use the result of a multi-select list box on
the form to feed multiple item numbers to the query.

In other words - if you pick item #100,105,110 from the list box, the query
should display information for those 3 items.

If I type 'IN (100,105,110)' in the criteria cell of the 'itemNo' field in
my query, it works - I get information for those 3 items. However, I would
like the list of items to be variable, coming from the items selected in the
multi-select list box on my form.

How do I loop through the items in the list box and feed them to the query?
What should I put in the criteria cell for my query?

Thanks very much,

Emma
Nov 12 '05 #1
4 2792
Take a look at http://www.mvps.org/access/forms/frm0007.htm at "The Access
Web"

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(No private e-mails, please)

"MSD" <ms*********@ho tmail.com> wrote in message
news:jweUb.4034 01$ts4.58439@pd 7tw3no...
I am running a report that uses a query as its record source and opens a
form collecting beginning and ending item numbers to feed to the query. This works, but now I'm trying to use the result of a multi-select list box on
the form to feed multiple item numbers to the query.

In other words - if you pick item #100,105,110 from the list box, the query should display information for those 3 items.

If I type 'IN (100,105,110)' in the criteria cell of the 'itemNo' field in
my query, it works - I get information for those 3 items. However, I would
like the list of items to be variable, coming from the items selected in the multi-select list box on my form.

How do I loop through the items in the list box and feed them to the query? What should I put in the criteria cell for my query?

Thanks very much,

Emma

Nov 12 '05 #2
Well, if you don't mind writing a little bit of code in your report you
could do something like this in the Report Open Event and Detail Event:

*************** *************** *************** *********
Option Compare Database
Option Explicit

Dim RS As Recordset

Private Sub Detail_Format(C ancel As Integer, FormatCount As Integer)
Text0 = RS(0)
RS.MoveNext
End Sub

Private Sub Report_Open(Can cel As Integer)
Dim frm As Form, ctl As Control,
Dim v As Variant, str1 As String, strSql As String
Set frm = Forms!Form1
Set ctl = frm!List16
For Each v In ctl.ItemsSelect ed
str1 = str1 & "'" & ctl.ItemData(v) & "',"
Next
str1 = Left(str1, Len(str1) - 1) 'get rid of last comma
Me.RecordSource = "Select fld1 From Table1 " _
& "Where fld1 In (" & str1 & ")"
strSql = "Select fld1 From Table1 " _
& "Where fld1 In (" & str1 & ")"
Set RS = CurrentDb.OpenR ecordset(strSql )
End Sub
*************** *************** *************** *********

In this example, the report is not directly bound to a recordsource.
You set the recordsource in the Report_Open event. I am only using one
field from a table, but you could select multiple fields and you filter
this recordset from the selections on the listbox on your form (which is
list16 in my example). You can use the

DoCmd.OpenRepor t "Report1" statement

and when Report1 open it will automatically read the selections from the
listbox. Then say you have 5 fields in the detail section of your
report, they could be txt0, txt1, txt2, txt3, txt4 or maybe you named
them

txtID, txtRegion, txtName, txtAddress, txtPhone

In the Detail section you would do this:

Private Sub Detail_Format(C ancel As Integer, FormatCount As Integer)
txtID = RS(0) 'or RS!ID
txtRegion = RS(1) 'or RS!Region
txtName = RS(2) 'or RS!Name
txtAddress = RS(3) 'or RS!Address
txtPhone = RS(4) 'or RS!Phone
RS.MoveNext
End Sub

And, of course, your sql statement in the report_open event would select
the same fields for the RecordSource and for the Recordset var (RS).

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #3
Thanks so much for your help. I think I'm close to having it work now.

I modified your code a bit - I create a string that contains the values
from the list box that I need for the parameter query. It looks like
this, e.g. 201,203,205.

In my parameter query, in the criteria cell for itemNo, I have :
In ([Forms]![frmSelectItems]![txtSelect])
where txtSelect is the name of the hidden control containing the string
'201,203,205' and frmSelectItems is the form with the list box and
hidden text box.

If I type:
In (201,203,205)
directly into the criteria cell, it works, however it doesn't work the
way I am doing it - even though the value of
[Forms]![frmSelectItems]![txtSelect] is 201,203,205.

Any ideas?

Thanks again,

Emma

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #4
Hi Emma,

This is the code I use to print from a multi-select box:

InSQL = CreateINClauseF romLB("lbListbo x", "frmSelectItems ",
ColWhereIDIsObt ainedFrom, NoPosted)
SQLString = "[FieldName] IN (" & InSQL & ")"
DoCmd.OpenRepor t ReportName, , , Filter
Msgbox NoPosted & "Item(s) printed"


Public Function CreateINClauseF romLB(LB As String, FormName As String, Col
As Long, ByRef Count As Long) As String
'Create an comma seperated string from the selected items in a list box
'Returns the no of items in the list in Count

Dim ItemIndex As Variant
Dim Tempst As String
If TestMode = False Then On Error GoTo ErrorHand

Count = 0

If (Forms(FormName )(LB).ItemsSele cted.Count < 1) Then
' If there are no items in the list, close form and exit procedure.
CreateINClauseF romLB = ""
Exit Function
End If

ItemIndex = 0

'Determine which listbox items are selected.
For Each ItemIndex In Forms(FormName) (LB).ItemsSelec ted
If Nz(Forms(FormNa me)(LB).Column( Col, ItemIndex), -1) > 0 Then
Tempst = Tempst & Format(Forms(Fo rmName)(LB).Col umn(Col, ItemIndex))
& ","
Count = Count + 1
End If
Next ItemIndex

'Ensure that temp string has some characters first, then remove last comma
If Tempst <> "" Then Tempst = Left(Tempst, Len(Tempst) - 1)

CreateINClauseF romLB = Tempst
Exit Function
ErrorHand:
EHD , MODULE_NAME
End Function

"Emma Danielson" <ms*********@ho tmail.com> wrote in message
news:40******** *************** @news.frii.net. ..
Thanks so much for your help. I think I'm close to having it work now.

I modified your code a bit - I create a string that contains the values
from the list box that I need for the parameter query. It looks like
this, e.g. 201,203,205.

In my parameter query, in the criteria cell for itemNo, I have :
In ([Forms]![frmSelectItems]![txtSelect])
where txtSelect is the name of the hidden control containing the string
'201,203,205' and frmSelectItems is the form with the list box and
hidden text box.

If I type:
In (201,203,205)
directly into the criteria cell, it works, however it doesn't work the
way I am doing it - even though the value of
[Forms]![frmSelectItems]![txtSelect] is 201,203,205.

Any ideas?

Thanks again,

Emma

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 12 '05 #5

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

Similar topics

37
4857
by: ajikoe | last post by:
Hello, Is anyone has experiance in running python code to run multi thread parallel in multi processor. Is it possible ? Can python manage which cpu shoud do every thread? Sincerely Yours, Pujo
4
4648
by: Frank Jona | last post by:
Intellisense with C# and a multi-file assembly is not working. With VB.NET it is working. Is there a fix availible? We're using VisualStudio 2003 Regards Frank
12
3857
by: * ProteanThread * | last post by:
but depends upon the clique: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=954drf%24oca%241%40agate.berkeley.edu&rnum=2&prev=/groups%3Fq%3D%2522cross%2Bposting%2Bversus%2Bmulti%2Bposting%2522%26ie%3DUTF-8%26oe%3DUTF-8%26hl%3Den ...
0
3763
by: frankenberry | last post by:
I have multi-page tiff files. I need to extract individual frames from the multi-page tiffs and save them as single-page tiffs. 95% of the time I receive multi-page tiffs containing 1 or more black and white CCITT4 compressed files (frames) inside the tiff. Every now and then I receive a mixture of black and white CCITT4 and JPEG compressed files, and sometimes just multi-page tiffs with JPEG only. The code runs great when dealing with the...
6
8156
by: cody | last post by:
What are multi file assemblies good for? What are the advantages of using multiple assemblies (A.DLL+B.DLL) vs. a single multi file assembly (A.DLL+A.NETMODULE)?
4
17842
by: mimmo | last post by:
Hi! I should convert the accented letters of a string in the correspondent letters not accented. But when I compile with -Wall it give me: warning: multi-character character constant Do the problem is the charset? How I can avoid this warning? But the worst thing isn't the warning, but that the program doesn't work! The program execute all other operations well, but it don't print the converted letters: for example, in the string...
5
5734
by: bobwansink | last post by:
Hi, I'm relatively new to programming and I would like to create a C++ multi user program. It's for a project for school. This means I will have to write a paper about the theory too. Does anyone know a good place to start looking for some theory on the subject of multi user applications? I know only bits and pieces, like about transactions, but a compendium of possible approches to multi user programming would be very appreciated!
17
10636
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, Wide character and multi-byte character are two popular encoding schemes on Windows. And wide character is using unicode encoding scheme. But each time I feel confused when talking with another team -- codepage -- at the same time. I am more confused when I saw sometimes we need codepage parameter for wide character conversion, and sometimes we do not need for conversion. Here are two examples,
0
2312
by: Sabri.Pllana | last post by:
We apologize if you receive multiple copies of this call for papers. *********************************************************************** 2008 International Workshop on Multi-Core Computing Systems (MuCoCoS'08) Barcelona, Spain, March 4 - 7, 2008; in conjunction with CISIS'08. <http://www.par.univie.ac.at/~pllana/mucocos08> *********************************************************************** Context
2
4650
by: Aussie Rules | last post by:
Hi, I have a site that Iwant to either display my text in english or french, based on the users prefernces ? I am new to webforms, but I know in winforms, this is pretty easy with a resource file. What is the best way to acheive this with webforms ?
0
7924
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
7854
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8219
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...
1
7978
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
5395
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();...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2364
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
1455
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1192
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.