473,387 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Multiselect Listbox

I have a simple multiselect listbox with a rowsorce of MemberID, MemberName,
SendLetter. SendLetter is a Yes/No field. What is the code to set SendLetter to
Yes when the user selects MemberName? I want to do this as the selections are
being made not after-the-fact after all selections are made.

Thanks!

Sally
Nov 13 '05 #1
2 6342

Hi Sally,
I'm hoping my reply will answer all of the posts that you have sent today
.... :-)

I like to use a multi-select list box to create a list of selections, then
use the In() operator to use this list as the criteria for the "query".

I say "query" because I am actually building a RecordSource for a
datasheet-style subform contained right in the same form as the listbox. As
items are progressively selected from the listbox , the subform instantly
refreshes to display them. Depending on how many records you select, this
can be very handy indeed.

My listbox also contains an "(All)" value, which can be selected to display
all records without any criteria.
See http://www.mvps.org/access/forms/frm0043.htm for the details on how to
do that, if you like.

This is the Row Source for the listbox that employs this method:

SELECT DISTINCTROW tblMembers.MemberID, tblMembers.MemberName FROM
tblMembers UNION Select "(All)" as null , "(All)" as Bogus From tblMembers;
----------------------------------------------------------------------------
---

And here is the code (tested and seems to be working fine) for the lisbox's
AfterUpdate event
************************************************** **************
Private Sub lstMembers_AfterUpdate()

'"Add All to List" Courtesy: Dev Ashish
' http://www.mvps.org/access/forms/frm0043.htm

Dim MyDB As DAO.Database
Set MyDB = CurrentDb

Dim ctl As Control
Set ctl = Me.lstMembers

Dim varItm As Variant
Dim strSelected As String

Dim MySQL As String
Dim whr As String

Dim Msg As String
Dim CR As String
CR = vbCrLf

'--------------------------Step
One -----------------------------------------------------
'Build an SQL string for use as the subform's Record Source, to show the
user which
'records have been selected from the listbox.

'Add a "safety" step which prevents the user from combining "All" with any
other criteria.
If ctl.ItemsSelected.Count > 1 And ctl.Selected(0) = True Then
Msg = ""
Msg = Msg & "You cannot select '(All)' along with " & CR
Msg = Msg & "any other criteria."
MsgBox (Msg)
ctl.Selected(0) = False
End If

'Build the list of selected MemberID's
For Each varItm In ctl.ItemsSelected

If Len(strSelected) > 0 Then
strSelected = strSelected & ", " & ctl.ItemData(varItm)
Else
strSelected = ctl.ItemData(varItm)
End If

Next varItm

'Debug.Print strSelected

MySQL = ""
MySQL = MySQL & "SELECT tblMembers.* FROM tblMembers "

whr = "" 'Clear the string variable

If Len(strSelected) > 0 And InStr(1, strSelected, "All") = 0 Then

whr = whr & "WHERE ((tblMembers.MemberID)In("
whr = whr & strSelected & ")"
whr = whr & ") "
End If

MySQL = MySQL & whr
MySQL = MySQL & "; "
'Debug.Print MySQL

Me.sbfMembers.Form.RecordSource = MySQL

'------------------------------ Step 2 ------------------------------
'Reset ALL "SendLetter" values to False.
'(We'll set the selected records to True in step 3)

MySQL = "" 'Reset the variable for re-use
MySQL = MySQL & "UPDATE tblMembers SET tblMembers.SendLetter = False "
MySQL = MySQL & "WHERE (((tblMembers.SendLetter)=True));"

MyDB.Execute MySQL, dbFailOnError

'------------------------------ Step 3 ------------------------------
'Set the selected values to "True"

MySQL = "" 'Reset the variable for re-use
MySQL = MySQL & "UPDATE tblMembers SET tblMembers.SendLetter = True "
MySQL = MySQL & whr 'Same WHERE statement created ealier. :-)
MySQL = MySQL & ";"

MyDB.Execute MySQL, dbFailOnError

Set MyDB = Nothing
Set ctl = Nothing

Me.Refresh

End Sub

************************************************** **************
--
HTH,
Don
=============================
Use My*****@Telus.Net for e-mail
Disclaimer:
Professional PartsPerson
Amateur Database Programmer {:o)

I'm an Access97 user, so all posted code
samples are also Access97- based
unless otherwise noted.

Do Until SinksIn = True
File/Save, <slam fingers in desk drawer>
Loop

================================

"Sally" <sm*****@earthlink.net> wrote in message
news:vl****************@newsread2.news.atl.earthli nk.net...
I have a simple multiselect listbox with a rowsorce of MemberID, MemberName, SendLetter. SendLetter is a Yes/No field. What is the code to set SendLetter to Yes when the user selects MemberName? I want to do this as the selections are being made not after-the-fact after all selections are made.

Thanks!

Sally

Nov 13 '05 #2
Don,

Thank you very, very much!!

I really appreciate your help.

Sally
"Don Leverton" <le****************@telusplanet.net> wrote in message
news:crKEc.58567$E84.37925@edtnps89...

Hi Sally,
I'm hoping my reply will answer all of the posts that you have sent today
... :-)

I like to use a multi-select list box to create a list of selections, then
use the In() operator to use this list as the criteria for the "query".

I say "query" because I am actually building a RecordSource for a
datasheet-style subform contained right in the same form as the listbox. As
items are progressively selected from the listbox , the subform instantly
refreshes to display them. Depending on how many records you select, this
can be very handy indeed.

My listbox also contains an "(All)" value, which can be selected to display
all records without any criteria.
See http://www.mvps.org/access/forms/frm0043.htm for the details on how to
do that, if you like.

This is the Row Source for the listbox that employs this method:

SELECT DISTINCTROW tblMembers.MemberID, tblMembers.MemberName FROM
tblMembers UNION Select "(All)" as null , "(All)" as Bogus From tblMembers;
----------------------------------------------------------------------------
---

And here is the code (tested and seems to be working fine) for the lisbox's
AfterUpdate event
************************************************** **************
Private Sub lstMembers_AfterUpdate()

'"Add All to List" Courtesy: Dev Ashish
' http://www.mvps.org/access/forms/frm0043.htm

Dim MyDB As DAO.Database
Set MyDB = CurrentDb

Dim ctl As Control
Set ctl = Me.lstMembers

Dim varItm As Variant
Dim strSelected As String

Dim MySQL As String
Dim whr As String

Dim Msg As String
Dim CR As String
CR = vbCrLf

'--------------------------Step
One -----------------------------------------------------
'Build an SQL string for use as the subform's Record Source, to show the
user which
'records have been selected from the listbox.

'Add a "safety" step which prevents the user from combining "All" with any
other criteria.
If ctl.ItemsSelected.Count > 1 And ctl.Selected(0) = True Then
Msg = ""
Msg = Msg & "You cannot select '(All)' along with " & CR
Msg = Msg & "any other criteria."
MsgBox (Msg)
ctl.Selected(0) = False
End If

'Build the list of selected MemberID's
For Each varItm In ctl.ItemsSelected

If Len(strSelected) > 0 Then
strSelected = strSelected & ", " & ctl.ItemData(varItm)
Else
strSelected = ctl.ItemData(varItm)
End If

Next varItm

'Debug.Print strSelected

MySQL = ""
MySQL = MySQL & "SELECT tblMembers.* FROM tblMembers "

whr = "" 'Clear the string variable

If Len(strSelected) > 0 And InStr(1, strSelected, "All") = 0 Then

whr = whr & "WHERE ((tblMembers.MemberID)In("
whr = whr & strSelected & ")"
whr = whr & ") "
End If

MySQL = MySQL & whr
MySQL = MySQL & "; "
'Debug.Print MySQL

Me.sbfMembers.Form.RecordSource = MySQL

'------------------------------ Step 2 ------------------------------
'Reset ALL "SendLetter" values to False.
'(We'll set the selected records to True in step 3)

MySQL = "" 'Reset the variable for re-use
MySQL = MySQL & "UPDATE tblMembers SET tblMembers.SendLetter = False "
MySQL = MySQL & "WHERE (((tblMembers.SendLetter)=True));"

MyDB.Execute MySQL, dbFailOnError

'------------------------------ Step 3 ------------------------------
'Set the selected values to "True"

MySQL = "" 'Reset the variable for re-use
MySQL = MySQL & "UPDATE tblMembers SET tblMembers.SendLetter = True "
MySQL = MySQL & whr 'Same WHERE statement created ealier. :-)
MySQL = MySQL & ";"

MyDB.Execute MySQL, dbFailOnError

Set MyDB = Nothing
Set ctl = Nothing

Me.Refresh

End Sub

************************************************** **************
--
HTH,
Don
=============================
Use My*****@Telus.Net for e-mail
Disclaimer:
Professional PartsPerson
Amateur Database Programmer {:o)

I'm an Access97 user, so all posted code
samples are also Access97- based
unless otherwise noted.

Do Until SinksIn = True
File/Save, <slam fingers in desk drawer>
Loop

================================

"Sally" <sm*****@earthlink.net> wrote in message
news:vl****************@newsread2.news.atl.earthli nk.net...
I have a simple multiselect listbox with a rowsorce of MemberID,

MemberName,
SendLetter. SendLetter is a Yes/No field. What is the code to set

SendLetter to
Yes when the user selects MemberName? I want to do this as the selections

are
being made not after-the-fact after all selections are made.

Thanks!

Sally


Nov 13 '05 #3

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

Similar topics

3
by: arthur-e | last post by:
Hi I'm trying to use a multiselect listbox to limit records in a report. My version at work is 97 but now at home I'm using Access2002- I know I can't go backwards ( to use this or similar code at...
2
by: Cassie Pennington | last post by:
I am trying to write various items from a multiselect list box to an SQL statement to update a report, without success. SQL only appears to accept hard-coded data or control values from a form, not...
2
by: Alan Lane | last post by:
Hello world: I'm using Access 2003. I have 2 listboxes. One is a single column. The other has two columns. I can use Dev Ashish's code (thanks Dev!) from the Access MVP Website to accumulate...
6
by: ¿ Mahesh Kumar | last post by:
Hi groups, Control name : ListboxID (lstCertification), selection mode=mutliselect. On Pageload i'm assinging string lstSplit="1/3/6/8" of the previously selected listindex id's. Now on the...
2
by: Steph | last post by:
I have created a multiselect list box control (lbx_comorb) that is populated from a datatable (dt_ptAdmission). The list box populates now problem at all. However the issue is when I load the...
2
by: ttime | last post by:
I've got a form that uses a multiselect listbox. When a user is selected from a combo box, values are populated into this listbox associated with that user. The problem is, if one person has say...
3
by: kaosyeti via AccessMonster.com | last post by:
hey... i have an unbound multiselect listbox on a form that i want to use to populate text boxes on that form. so if a user selects the 3rd item in a list of 20, how can i have that item show up...
5
by: martin DH | last post by:
Hello, The details are below, but I have a simple form (Form1) with two objects and a "search" command button. When the two objects are cascading combo boxes (the form creates the parameters for a...
1
by: asharma0001 | last post by:
Hi all, I was wondering whether somebody might be able to help me with a question I have on a MS Access Database I'm building. I have created a search form with a few multiselect listboxes....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...

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.