473,782 Members | 2,396 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is this possible? - update a true/false field using listbox

50 New Member
Hi experts, I'm hoping you can help me with this.. I have recently found out how to use the INSERT INTO statement to add multiple records from a listbox to a table, I now need to UPDATE records in another table using a multi-select listbox.

Problem:

I want to present a template of working hours of staff by showing 48 x 30minute intervals, each as a row in a listbox. My idea is that if the person usually works 9am till 5pm, there is a yes / no in the relevant field in the table. I then want the working hours to be modified in the form of a listbox where when loaded it shows the 9-5 rows selected, and it can be modified by selecting more rows / deselecting rows, then saved and the table updated.

...I know how to do it with check / option boxes and i'm sure it can be done with multiselect list boxes but I just don't know how?

Hope you can help, OllyJ
Dec 20 '07 #1
11 4276
nico5038
3,080 Recognized Expert Specialist
Guess my sample gives you the idea:
http://www.geocities.com/nico5038/xS...p-Down2000.zip

Just check the use of multiple row selection and the values in the fields at the bottom of the form. (SelStart and SelLength)

Nic;o)
Dec 31 '07 #2
OllyJ
50 New Member
Thanks for your response Nico, much appreciated. I have had a look at your sample db...

I understand how you have updated the list boxes in FrmMoveLeftRigh t (SQL in RowSource) to get the 'true' values in one listbox and the 'false' values in the other. What I need to do is to have all values in one single listbox but on loading the form, the values that are 'true' to be selected and those that are 'false' not selected but still visible.

I hope you can help, many thanks in advance

OllyJ
Jan 2 '08 #3
nico5038
3,080 Recognized Expert Specialist
The sample database not only shows how to move the records, but more important for you, also how a selection of multiple rows will be recognized.
I would change the sample for your needs by changing the recordsource of the first listbox into selecting all (both true and false) and show the True/False field. The other listbox can be dropped entirely.

Finally you can use the True/False to fill a field that's holding always 48 characters (one for each 30 minutes) with "+" and "-" signs to record the working hours.
Personally I would write two functions:
1) To translate the temporary "hours table" into the 48 charater string
2) To transform the string into 48 records with True and False.

Getting the idea ?

Nic;o)
Jan 2 '08 #4
OllyJ
50 New Member
Nic

I am beginning to get the idea however I apologise for my slow take up as I am still very much a novice compared to most and am having to learn as I go.

I'll tell you where i'm at...

I have a table with 2 fields... 'Hours' and 'YesNo'... within 'Hours' there are 48 records (1 for each 30 minutes)... 'YesNo' has a Yes/No data type (there's a surprise!)

Then I have a form bound to that table. In it I have a listbox that contains all of the records for the 'Hours' field. *** I am now struggling with the hard bit - getting the listbox to select those that are true on load of the form and allow editing by selecting / deselecting on listbox and clicking save command button. ***

I am not sure what the two functions that you speak of would do, have I already covered that with how I have set up the table/listbox?

Again, i apologise for my lack of understanding and hope you can help me with this.

OllyJ
Jan 2 '08 #5
nico5038
3,080 Recognized Expert Specialist
I was under the impression you needed to store the values into one field, thus my proposal for the "code/decode" functions.

I would add a Sequence field to your tblHours so it will hold:
Sequence (Integer 1 till 48)
Hour (Text 0:00 till 23:30)
YesNo (Boolean)

Now you can initialize this table for 9 to 5 using two UPDATE queries like:
UPDATE tblHours Set YesNo = False;
and
UPDATE tblHours Set YesNo = True Where Sequence between 18 and 34;

Finally define a multiselect listbox with the three fields and add a button with the code:

Expand|Select|Wrap|Line Numbers
  1. Dim varItm
  2. For Each varItm In Me.lbxTableName.ItemsSelected
  3.    CurrentDb.Execute ("Update tblHours set YesNo = NOT YesNo where Sequence=" & Me.lbxTableName.Column(0, varItm))
  4. Next
  5. Me.lbxTableName.Requery
  6.  
This wil toggle the YesNo field, but you could ofcourse also use two buttons for setting true and false...

Nic;o)
Jan 2 '08 #6
OllyJ
50 New Member
I am sorry Nic but I am still struggling to get my head round it. I know I am now into code way above my knowledge level but just have to get this thing done so bear with me please :)....

I understand about adding a sequence column as an 'ID' so to speak.

A couple of questions though

1. Are the queries essential to run the code? Because rather than update to 9-5 I need the user to have complete flexibility by just selecting and deselecting from the multiselect listbox.

2. I tried this code and played with it but kept getting syntax errors....

What does the 'SET YesNo=NOT YesNo' do? I also tried a simple 'SET YesNo = Yes Where...' but couldn't get that to work either.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command40_Click()
  2.  
  3. Dim varItm
  4.  
  5. For Each varItm In Me.List38.ItemsSelected
  6.    CurrentDb.Execute ("UPDATE Table1 SET YesNo = NOT YesNo WHERE Sequence= Me.List38.Column(0, varItm)")
  7.  
  8. Next
  9. Me.List38.Requery
  10.  
  11. End Sub

Also... i've been trying with code for the on current of the form to get those that are 'YES' in the YesNo field to automatically be selected and cannot do that either.

Sorry if you are losing patience :) , i am trying v.hard this end.

OllyJ
Jan 2 '08 #7
nico5038
3,080 Recognized Expert Specialist
I am sorry Nic but I am still struggling to get my head round it. I know I am now into code way above my knowledge level but just have to get this thing done so bear with me please :)....

I understand about adding a sequence column as an 'ID' so to speak.

A couple of questions though

1. Are the queries essential to run the code? Because rather than update to 9-5 I need the user to have complete flexibility by just selecting and deselecting from the multiselect listbox.

2. I tried this code and played with it but kept getting syntax errors....

What does the 'SET YesNo=NOT YesNo' do? I also tried a simple 'SET YesNo = Yes Where...' but couldn't get that to work either.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command40_Click()
  2.  
  3. Dim varItm
  4.  
  5. For Each varItm In Me.List38.ItemsSelected
  6.    CurrentDb.Execute ("UPDATE Table1 SET YesNo = NOT YesNo WHERE Sequence= Me.List38.Column(0, varItm)")
  7.  
  8. Next
  9. Me.List38.Requery
  10.  
  11. End Sub

Also... i've been trying with code for the on current of the form to get those that are 'YES' in the YesNo field to automatically be selected and cannot do that either.

Sorry if you are losing patience :) , i am trying v.hard this end.

OllyJ
1) No queries aren't necessary, but I would use them to initialize the hours so the user doesn't have to select them for the obvious timespan.
An alternative would be to use only the SET YesNo = False to make sure no old setting remains.
2) 'SET YesNo=NOT YesNo' will switch the value.
When True it becomes False and vise versa.

For testing the needed query use the query text in a new query. (Open a new query, select NO table and press the appearing SQL-button top left)
Just copy/paste:
UPDATE Table1 SET YesNo = NOT YesNo WHERE Sequence = 1;
and press the exclamation button [ ! ] to execute the query.
When something is wrong you'll get a warning.

Keep me posted.

Nic;o)
(PS patience is my middle name :-)
Jan 2 '08 #8
OllyJ
50 New Member
Nic

Thanks for your help, I am now able to run this code...
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command10_Click()
  2.  
  3. Dim varItm
  4.  
  5. For Each varItm In Me.List6.ItemsSelected
  6. CurrentDb.Execute ("UPDATE [Table1] SET [YesNo] = Yes WHERE [Sequence] =" & Me.List6.Column(2, varItm))
  7.  
  8. Next
  9. Me.List6.Requery
  10.  
  11. End Sub
... I have played around this afternoon for ages trying to find a way to...

Firstly, how to automatically select rows if YesNo is 'true' on loading of the form.

Secondly, how the set the whole YesNo field to 'No' before executing the above code.

If you can help me with these it will be great.

Thanks again for your help so far.

OllyJ
Jan 2 '08 #9
nico5038
3,080 Recognized Expert Specialist
The problems:
1) Firstly, how to automatically select rows if YesNo is 'true' on loading of the form.
> This is only needed when the "false" rows aren't stored, else all rows an be used. Personally I would probably use a temporary table with the 48 rows and a "decode" function to store the result of the 48 character field into tose rows.
Basically I need to know how your tables have been designed and what way you want to manipulate the data.

2) Secondly, how the set the whole YesNo field to 'No' before executing the above code.
> Initializing the whole temp table is done by:
UPDATE tblHours SET YesNo = False;

Nic;o)
Jan 2 '08 #10

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

Similar topics

9
4778
by: Pam Ammond | last post by:
I need the code to update the database when Save is clicked and a text field has changed. This should be very easy since I used Microsoft's wizards for the OleDBAdapter and OleDBConnection, and DataSet; and all I'm doing is showing one record in text fields, allowing the user to modify the text fields, and then updating the database again when the user clicks the Save button. The fields already show the correct data record since I have...
1
8422
by: Edward | last post by:
I am having a terrible time getting anything useful out of a listbox on my web form. I am populating it with the results from Postcode lookup software, and it is showing the results fine. What I want to do is to allow the user to click on the row that corresponds to the correct address, and have the code behind populate the form's Address1, Address2 etc. controls with the relevant data items. I put the code for this into the...
25
4073
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
5
2300
by: heddy | last post by:
I have a listbox that gets populated in code by a reader result set from a stored proc on SQL Server 2005. In building this I created a set of test rows in the DB and the code runs fine and populates the box. Next I added functionality to add data. This adds data to the DB and then forces the listbox to refresh by clearing it's contents and then re-running the populate code. However, when I add an item and do the refresh, the listbox...
5
2179
by: explode | last post by:
I made a procedure Public Sub Novo(ByVal nova1 As String, ByVal nova2 As String) that creates a new oledbDataAdapter with insert update select and delete commads. I also added that commands can change depending how many columns are in a Table. I add a new column with this code: Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Try...
9
7751
bhcob1
by: bhcob1 | last post by:
Hey guys, 'Update or CancelUpdate without AddNew or Edit' On my database i keep occasionly get this error when i try and edit a field, it is not everytime. It will be working fine and then this error appears. I will be editing records and then a random one will get the error. A bit of background on my form, this will seem a bit lengthy but here is my code. The form has a navigation list which the user can select a record to view. An...
2
3833
by: rrflore2 | last post by:
Ok. I'm writing and deleting to an xml file using a dataset. I have a function in my codebehind page that binds a listbox to the dataset that performs the writes/deletes. Everything seems to be working fine except, I cannot get the listbox to update after the xml file is written to. I've tried to rebind the listbox and a bunch of other things; nothing seems to work. I'm sure this is simple fix but, I cannot seem to figure it out. I...
7
2408
by: BONES7714 | last post by:
Hello, This is my first post to any sort of forum although I've used them to learn the very little Access/VBA that I know so please forgive my ignorance. I work for the National Guard as Combat Medic and I've been tasked with created a DB to track the location of other soldiers medical records and other various infomation. As such, I have a form where I can enter the barcode for a record into a textbox and have it added to a listbox and...
4
2907
by: justice750 | last post by:
Hi All, I am using a FormView control. The allows me to update records in the database. However, when a database field is null I can not update the field on the form. It works fine when the field is not a null value. I am not using any code behind (C#) to bind the data or manipulate the data. I have read that when there is a null value in the database that there is no record in the "dataset". Can anyone show me how to bind a value in the...
0
9641
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
9480
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
10313
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
9944
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
7494
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
6735
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
5378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2875
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.