473,769 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiselect Listbox selection and update flag in table

1 New Member
I ahve two multiselect listbox for filtering report and printing.

Now i want to update my table with flag saying its being printed and when the form is loaded again the flagged records should be filtered.How do i write VbA code for this.

Can anyone help me please.

I have been trying to get correct code for this.
Thanks in advance.
Dec 19 '07 #1
3 4089
PianoMan64
374 Recognized Expert Contributor
Can you provide a little more detail as to how you're using the comboboxes to filter the output of the reports.

Are you using both combo boxes and clicking some button to being printing?

If that is the case, then you simply need to update the field that you're using for your Flag and then once those flags are set, then you have another flag that says they are printed, and update that as well.

The other change I would make would be to make the combo boxes into ListControls that way you can see what items you've selected to print.

Expand|Select|Wrap|Line Numbers
  1. 'this code will go into the form that has the combo boxes
  2. 'Requires reference to Microsoft DAO 3.6 or Higher Library.
  3. 'Simply get into code editor, click tools > Reference and select Microsoft DAO 3.x depending on what version of access you have installed.
  4. Function SetFlag(PrimaryKey as Double) 
  5.     Dim MyDB as DAO.Database
  6.     Dim MyRS as DAO.RecordSet
  7.  
  8.     Set MyDB = CurrentDB()
  9.     Set MyRS = MyDB.OpenRecordset("SELECT * FROM [Table Name] " & _
  10.                               "WHERE [Field Name of Primary Key] = " & PrimaryKey _
  11.                               , dbOpenDynaset)
  12.  
  13.     With MyRS
  14.                If Not .EOF Then
  15.                         .Edit
  16.                         !TheFlagFieldName = True
  17.                         .Update
  18.                End if
  19.      End With
  20.  
  21.      MyRS.Close
  22.      MyDB.Close
  23.  
  24.      Set MyRS = Nothing
  25.      Set MyDB = Nothing
  26.  
  27. End Function
  28.  
  29. Function SetPrintedFlag(PrimaryKey as Double) 
  30.     Dim MyDB as DAO.Database
  31.     Dim MyRS as DAO.RecordSet
  32.  
  33.     Set MyDB = CurrentDB()
  34.     Set MyRS = MyDB.OpenRecordset("SELECT * FROM [Table Name] " & _
  35.                               "WHERE [Field Name of Primary Key] = " & PrimaryKey _
  36.                               , dbOpenDynaset)
  37.  
  38.     With MyRS
  39.                If Not .EOF Then
  40.                         .Edit
  41.                         !TheFlagFieldName = True
  42.                         .Update
  43.                End if
  44.      End With
  45.  
  46.      MyRS.Close
  47.      MyDB.Close
  48.  
  49.      Set MyRS = Nothing
  50.      Set MyDB = Nothing
  51.  
  52. End Function
  53.  
This will get you started. What I need to find out from you now in order to finish this example is, are you using the combo boxes to use them as filters to what you're going to print, or are these combo boxes records that are in a table that you want to select and print?

let me know and I can give you the rest of the code.

Hope this helps,

Joe P.
Jan 5 '08 #2
uconn12
1 New Member
How do I update a flag in a table based on a listbox? I have a multi select list box, the user selects multiple rows in the list box, then clicks a button. Based on the rows selected, I want the flag in a table for those rows to change from Yes to No.
Thanks
Oct 20 '08 #3
GazMathias
228 Recognized Expert New Member
You need to get each ID from the list, then build an UPDATE SQL statement like this:


Get each ID in the list (where ListName is the name of your list):
Expand|Select|Wrap|Line Numbers
  1. For Each varItem In Me!ListName.ItemsSelected
  2. strCriteria = strCriteria & "FieldInTableName = " & Me!ListName.ItemData(varItem) & " OR "
  3. Next varItem
(Make sure that the listbox has the column bound to the ID you want recorded).

Remove the last "OR ", cos we don't need it:
Expand|Select|Wrap|Line Numbers
  1. strCriteria = Left(strCriteria, Len(strCriteria) - 3)
Update the table:
Expand|Select|Wrap|Line Numbers
  1. strSQL = "UPDATE TableName SET Flag = True WHERE "
  2. strSQL = strSQL & strCriteria & ";"
  3. DoCmd.RunSQL strSQL
I prefer the "strSQL = strSQL &" method over the "&_" because I find it easier to read, but that is of course user preference and you can do it the way you feel comfortable with.
Oct 20 '08 #4

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

Similar topics

2
5798
by: Fatou | last post by:
I have a listbox where the user selects only one value at a time. The problem is that once the user selects the value and the record is updated in the table, they can reselect the same value again. I do not want this to happen. Your input is greatly appreciated.
2
6368
by: Sally | last post by:
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
2
3357
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 variable data. Any clues as to how I can write several items to an SQL statement from a multiselect listbox to update a report? Thanks in anticipation Cassie
0
1152
by: deejayquai | last post by:
Hi I'm moving forward with a topic I've posted a couple of time before but still haven't cracked it, any further help is much appreciated. In a nutshell, I want to append either 1 or a selection of group members with either 1 or a selection of activity names into a assessment table called- tblAssessmentActivityProfile from 2 multiselect listboxes on a form. is the primary key I wish to append from
1
2466
by: Gianluca | last post by:
This works well on a single selection listbox: protected override OnMouseDown(...) { base.OnMouseDown(...); MessageBox.Show(this.SelectedIndex.ToString()); } But on a multiple selection listbox you get a IndexOutOfRange exception. Which is not documented as a possible exception being thrown by accessing
6
1711
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 page load for updation, i have to reload the selected items again with the same string "1/3/6/8" to be selected in my multiselect list box. Its asking me to convert object to int... for list selection. but how to achieve this..?...
1
3302
by: JNariss | last post by:
Hello, I have created a form called frmS2P with the following: 1 listbox called List11 which holds the contents of a query created off my table called tblRequestActions. The fields which the listbox holds are Request_ID and MoveNumber. 1 text box called Date which is populated with the default value of =Date( ).
3
3628
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 in a text box? then, how can i have a second selected item show up in a different text box, without affecting the 1st one? (lboxOptions, txtboxOptions0, txtboxOptions1, etc..) -- Greg Message posted via AccessMonster.com
1
1852
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. What I'd ultimately like is for the selection(s) in one listbox to filter the second listbox, but am struggling to find a way to do this. I have looked at some of the other solutions on this forum but not been able to find one that works on my database....
0
9589
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
9423
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
10045
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...
0
9863
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...
1
7408
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6673
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();...
1
3958
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
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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.