473,322 Members | 1,526 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,322 software developers and data experts.

Store old value of an unbound list box?

Hi,

I need to store the last value of an unbound list box. For example, if the list box is currently set to X, when a user clicks Y, I need to save X in a variable.

I've tried to store the old value in a variable during the Before Update event, but that does work. I've also heard that the OldValue property doesn't work on unbound controls.

Anyone know how to do this?
Thanks,
Adam
Dec 9 '09 #1
6 10307
ChipR
1,287 Expert 1GB
You might hide a text box on the form and update its value when an item is selected, after getting the old value.
Dec 9 '09 #2
ChipR,

Thanks for the reply. That's kind of the the approuch I took, but I because I couldn't find an event to capture the value at the moment of the click, I needed 2 text boxes. Here's my solution:

Expand|Select|Wrap|Line Numbers
  1. Private Sub lstbMyListBox_AfterUpdate()
  2.  
  3.         'store the last value
  4.         !txbLastID = !txbCurrentID
  5.         !txbCurrentID = !lstbMyListBox
  6.  
  7. End Sub
  8.  

It works, but I can't help feeling there is a better way to do this.

Thanks,
Adam
Dec 9 '09 #3
Stewart Ross
2,545 Expert Mod 2GB
One approach if you want to store the original value of the control as it was when the control gets focus would be to use the On Enter event of the listbox control to store the current value of the list into the Tag property of the same control. You can then reference the control's previous value by listing its Tag property, and its current value by listing its Value property (the default when referring to the control).

For a test control (simply called lstTest in my example), the On Enter code is just

Expand|Select|Wrap|Line Numbers
  1. Private Sub lstTest_Enter()
  2.     Me.lstTest.Tag = Nz(Me.lstTest, "Null")
  3. End Sub
The Nz is necessary because when the control gains focus the On Enter event will be fired, and as no selection has been made the listbox has a null value which cannot be stored in the Tag property.

In testing this here is an After Update event routine which prints out the current and previous values to the VBE immediate window:

Expand|Select|Wrap|Line Numbers
  1. Private Sub lstTest_AfterUpdate()
  2.     Debug.Print "Current: " & Nz(Me.lstTest, "Null") & " Prev: " & Me.lstTest.Tag
  3. End Sub
  4.  
Please note that On Enter fires just once until the control loses focus, whereas After Update will be fired several times if the user makes choices from the control one after the other (see first three examples and next two examples below):

Expand|Select|Wrap|Line Numbers
  1. Current: eastgate Prev: Null     
  2. Current: PUMPGATE COURT Prev: Null          (selected straight after the first selection without leaving the control)
  3. Current: BROOM DRIVE Prev: Null             (as above)
  4. Current: HIGH STREET Prev: BROOM DRIVE      (selected after leaving the control to do something else)
  5. Current: ISLAND BANK ROAD Prev: BROOM DRIVE (selected without leaving the control)
  6. Current: B9006 Prev: ISLAND BANK ROAD       (selected after leaving the control to do something else)
  7. Current: Croy Prev: B9006                   (selected after leaving the control to do something else)
-Stewart
Dec 10 '09 #4
Stewart,

Yes, you see the problem. I tried the OnEnter and the GotFocus events, but I saw it didn't work if the user made additional selections. I knew it was going to have to involve AfterUpdate. Ultimately, using the 2 text boxes seems to be the only thing that works consistently. Odd that there is no way to access OldValue, but I have it working so onward and upward.

Thanks,
Adam
Dec 10 '09 #5
mkaney
1
Just save the value to a variable in the current event and in the after update event. Then the next time the user changes it, the new value will not have copied to the variable until after the update, so the old value will be in the variable in the before update event. Just make sure to put the variable at the top of the form module above any subs so that it is available to all subs in the module.
Dec 15 '09 #6
i am a newbie with Access. I like to create a form to store user configuration. How to transfer and store those user-select value? should i store them in a table?

and, during operation, how to retrieve those value?

thank you.
Feb 22 '10 #7

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

Similar topics

3
by: Newbie | last post by:
Hi all, A have several forms with unbound combo boxes, the combo boxes are used to filter the data in the forms. What I would want is that my application stores the most recent settings of these...
0
by: Evets Htims | last post by:
I have an order form (frmOrder on tblOrder) with a series of sub forms in tabs that list items (from tblOrderItems) associated (by OrderID) with the order. I have 4 classes of items, so when the...
8
by: Zlatko Matiæ | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
10
by: MLH | last post by:
Would like to examine the value entered into a textbox on an A97 form during the BeforeUpdate event. The textbox may or may not have had an earlier entry in it prior to the latest value that is...
8
by: Robert | last post by:
I have a form (Worksheet) that works fine by itself. I have now created a seperate form (MainForm) that has a command button in the header and an unbound subform (FormFrame) in the Detail section....
0
by: colleen1980 | last post by:
Hi: There are two textboxs in my main form. One is bound and another is unbound. There is no entry in the unbound textbox as values come into automatically after entering some information in the...
3
by: Richard | last post by:
How is the result of query placed in a unbound textbox ? Suppose CriteriaLookups has columns TableName, KeyColumn, KeyValue, DataColumn Foo,x,11,xhat Bar,z,3,xyzzy And
1
by: solargovind | last post by:
Hi, I need to store the Value of unbound Textbox control value into my table. Because, I hve calculated Due date of Vendor's from the Invoice date which i also need to store into my table. ...
9
by: Ajinkya | last post by:
Hello friends ! , I am very new to java script.If anyone can help me then I will be very very thankful to his/her. I am using php and mysql in my project and I have one textarea and one...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.