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.
3 4089
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. -
'this code will go into the form that has the combo boxes
-
'Requires reference to Microsoft DAO 3.6 or Higher Library.
-
'Simply get into code editor, click tools > Reference and select Microsoft DAO 3.x depending on what version of access you have installed.
-
Function SetFlag(PrimaryKey as Double)
-
Dim MyDB as DAO.Database
-
Dim MyRS as DAO.RecordSet
-
-
Set MyDB = CurrentDB()
-
Set MyRS = MyDB.OpenRecordset("SELECT * FROM [Table Name] " & _
-
"WHERE [Field Name of Primary Key] = " & PrimaryKey _
-
, dbOpenDynaset)
-
-
With MyRS
-
If Not .EOF Then
-
.Edit
-
!TheFlagFieldName = True
-
.Update
-
End if
-
End With
-
-
MyRS.Close
-
MyDB.Close
-
-
Set MyRS = Nothing
-
Set MyDB = Nothing
-
-
End Function
-
-
Function SetPrintedFlag(PrimaryKey as Double)
-
Dim MyDB as DAO.Database
-
Dim MyRS as DAO.RecordSet
-
-
Set MyDB = CurrentDB()
-
Set MyRS = MyDB.OpenRecordset("SELECT * FROM [Table Name] " & _
-
"WHERE [Field Name of Primary Key] = " & PrimaryKey _
-
, dbOpenDynaset)
-
-
With MyRS
-
If Not .EOF Then
-
.Edit
-
!TheFlagFieldName = True
-
.Update
-
End if
-
End With
-
-
MyRS.Close
-
MyDB.Close
-
-
Set MyRS = Nothing
-
Set MyDB = Nothing
-
-
End Function
-
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.
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
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): - For Each varItem In Me!ListName.ItemsSelected
-
strCriteria = strCriteria & "FieldInTableName = " & Me!ListName.ItemData(varItem) & " OR "
-
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: - strCriteria = Left(strCriteria, Len(strCriteria) - 3)
Update the table: - strSQL = "UPDATE TableName SET Flag = True WHERE "
-
strSQL = strSQL & strCriteria & ";"
-
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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.
|
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
|
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
|
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
|
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
| |
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..?...
|
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( ).
|
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
|
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....
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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();...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |