473,320 Members | 2,027 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,320 software developers and data experts.

ListBox item.selected background stays black

I have four listboxes on my form. When I add a new record, I run the following code to clear list box items...

Expand|Select|Wrap|Line Numbers
  1. Public Function ClearAll()
  2. 'This function clears ALL selected fields in the [BillExpUpdate] form's workspace.
  3. Dim var As Variant
  4.  
  5.     For Each var In Forms![BillExpUpdate].[lst1st_Bills].ItemsSelected
  6.     Forms![BillExpUpdate].[lst1st_Bills].Selected(var) = False
  7. Next
  8.     For Each var In Forms![BillExpUpdate].[lst1st_Exp].ItemsSelected
  9.     Forms![BillExpUpdate].[lst1st_Exp].Selected(var) = False
  10. Next
  11.     For Each var In Forms![BillExpUpdate].[lst15th_Bills].ItemsSelected
  12.     Forms![BillExpUpdate].[lst15th_Bills].Selected(var) = False
  13. Next
  14.     For Each var In Forms![BillExpUpdate].[lst15th_Exp].ItemsSelected
  15.     Forms![BillExpUpdate].[lst15th_Exp].Selected(var) = False
  16. Next
  17. End Function
  18.  
I do this so that my form "looks" clean when I update. The irritation is that even though it "deselects" all the list boxes, as soon as I add a new record, it adds a black box to all the previously selected listbox rows? I don't get it. I'm not sure what is "storing" this info, but I would very much like to get rid of it, but don't know how.

I know that when the form loads initially, it isn't a problem... I can add a new record and the boxes remain clear... so I know it isn't tied to the "add record" function. Any suggestions anyone? Thanks in advance.
Nov 17 '07 #1
5 4617
puppydogbuddy
1,923 Expert 1GB
I have four listboxes on my form. When I add a new record, I run the following code to clear list box items...

Expand|Select|Wrap|Line Numbers
  1. Public Function ClearAll()
  2. 'This function clears ALL selected fields in the [BillExpUpdate] form's workspace.
  3. Dim var As Variant
  4.  
  5.     For Each var In Forms![BillExpUpdate].[lst1st_Bills].ItemsSelected
  6.     Forms![BillExpUpdate].[lst1st_Bills].Selected(var) = False
  7. Next
  8.     For Each var In Forms![BillExpUpdate].[lst1st_Exp].ItemsSelected
  9.     Forms![BillExpUpdate].[lst1st_Exp].Selected(var) = False
  10. Next
  11.     For Each var In Forms![BillExpUpdate].[lst15th_Bills].ItemsSelected
  12.     Forms![BillExpUpdate].[lst15th_Bills].Selected(var) = False
  13. Next
  14.     For Each var In Forms![BillExpUpdate].[lst15th_Exp].ItemsSelected
  15.     Forms![BillExpUpdate].[lst15th_Exp].Selected(var) = False
  16. Next
  17. End Function
  18.  
I do this so that my form "looks" clean when I update. The irritation is that even though it "deselects" all the list boxes, as soon as I add a new record, it adds a black box to all the previously selected listbox rows? I don't get it. I'm not sure what is "storing" this info, but I would very much like to get rid of it, but don't know how.

I know that when the form loads initially, it isn't a problem... I can add a new record and the boxes remain clear... so I know it isn't tied to the "add record" function. Any suggestions anyone? Thanks in advance.

try using the following code behind your form (not in a public module) in place of your code. It will loop the controls collection for your form.

Expand|Select|Wrap|Line Numbers
  1. sub ClearListBoxes()
  2. dim x, ctl as control
  3.  
  4. for each ctl in me.controls
  5.   if ctl.controltype=aclistbox then
  6.        with me(ctl.name)
  7.                for each x in .itemsselected
  8.                      .selected(x)=false
  9.                 next
  10.         end with
  11.   end if
  12. next
  13. end sub
Nov 17 '07 #2
try using the following code behind your form (not in a public module) in place of your code. It will loop the controls collection for your form.

Expand|Select|Wrap|Line Numbers
  1. sub ClearListBoxes()
  2. dim x, ctl as control
  3.  
  4. for each ctl in me.controls
  5.   if ctl.controltype=aclistbox then
  6.        with me(ctl.name)
  7.                for each x in .itemsselected
  8.                      .selected(x)=false
  9.                 next
  10.         end with
  11.   end if
  12. next
  13. end sub
The code worked great! But now when I dbl_click my txtbox to add new record, I get an "Update or CancelUpdate without AddNew or Edit" Error when I tab off of the txt box to enter the next data field? Argg.... I've tried everything I can think of to stop it... any other ideas? Here's what my code looks like for the add record function.

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtBill_Name_DblClick(Cancel As Integer)
  2. On Error GoTo Err_txtBill_Name_DblClick
  3.  
  4. 'Add/Saves New record
  5.     DoCmd.GoToRecord , , acNewRec
  6.     DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
  7.  
  8. Exit_txtBill_Name_DblClick:
  9. ClearList
  10. ScanBox
  11. Exit Sub
  12.  
  13. Err_txtBill_Name_DblClick:
  14.     MsgBox Err.Description
  15.     Resume Exit_txtBill_Name_DblClick
  16. End Sub
Again, any help would be greatly appreciated...
Nov 17 '07 #3
puppydogbuddy
1,923 Expert 1GB
The code worked great! But now when I dbl_click my txtbox to add new record, I get an "Update or CancelUpdate without AddNew or Edit" Error when I tab off of the txt box to enter the next data field? Argg.... I've tried everything I can think of to stop it... any other ideas? Here's what my code looks like for the add record function.

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtBill_Name_DblClick(Cancel As Integer)
  2. On Error GoTo Err_txtBill_Name_DblClick
  3.  
  4. 'Add/Saves New record
  5.     DoCmd.GoToRecord , , acNewRec
  6.     DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
  7.  
  8. Exit_txtBill_Name_DblClick:
  9. ClearList
  10. ScanBox
  11. Exit Sub
  12.  
  13. Err_txtBill_Name_DblClick:
  14.     MsgBox Err.Description
  15.     Resume Exit_txtBill_Name_DblClick
  16. End Sub
Again, any help would be greatly appreciated...
There several possiblities:
1. Try substituting null or spaces ("") for false in the clear listbox code I gave you above. Setting it false may represent a value that has to be saved. If that does not work, you could add the following code line in the clear listbox code to force a save after setting it false.

If me.Dirty then
me.Dirty = False
End If

2. Do you have code in a BeforeUpdate Event that is updating anything? If so, it should be moved to an afterUpdate event.
3. Are you updating a recordset? You need to use the .Edit/.Update methods to effect the update.

Also, although it does not cause an error, the following syntax is outdated and may be phased out:

DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

you should use:

DoCmd.RunCommand acCmdSaveRecord
Nov 17 '07 #4
missinglinq
3,532 Expert 2GB
PDB, your point about the DoCmd.DoMenuItem code is well made! Despite the fact that Micro$oft uses this type of code for much of the Command Button Wizard's creations, rumors of its demise have been around for years, and eventually, probably without warning, they will drop support for it altogether! But having an inquiring mind (well, the little bit of gray matter that is still viable is inquiring) I have to ask you this: Why would you, in a single post, suggest to the OP that they use

If me.Dirty then
Me.Dirty = False
End If

in one place, and

DoCmd.RunCommand acCmdSaveRecord

in another, since they both perform the save function, implicitly forcing a record save? Is there something about one method or the other that I don't know about?

Welcome to TheScripts, luengelj!

Linq ;0)>
Nov 17 '07 #5
puppydogbuddy
1,923 Expert 1GB
PDB, your point about the DoCmd.DoMenuItem code is well made! Despite the fact that Micro$oft uses this type of code for much of the Command Button Wizard's creations, rumors of its demise have been around for years, and eventually, probably without warning, they will drop support for it altogether! But having an inquiring mind (well, the little bit of gray matter that is still viable is inquiring) I have to ask you this: Why would you, in a single post, suggest to the OP that they use

If me.Dirty then
Me.Dirty = False
End If

in one place, and

DoCmd.RunCommand acCmdSaveRecord

in another, since they both perform the save function, implicitly forcing a record save? Is there something about one method or the other that I don't know about?

Welcome to TheScripts, luengelj!

Linq ;0)>
Hi Linq,
I guess a clarification is in order.

On the one hand, I recommended the If Me.Dirty code as a solution for the OP's problem if setting the listbox items to null or to spaces in lieu of false continued to generate the save/cancel message. This recommendation was based on the presumption that if setting the Listbox items to null or spaces did not alleviate the problem, then Access must still consider the form to be Dirty...and, therefore the If Me.Dirty syntax was appropriate in this context because it is an "implicit" save, and not an "explicit" save like DoCmd.RunCommand acSaveRecord.

On the other hand, the OP (not me) stated that he tried the DoCmd.DoMenuItem and that didn't work. In that context, I was trying to tell him: oh , by the way he ought to be aware that the DoCmd.DoMenuItem syntax was outdated, although still allowed to be used.
Nov 17 '07 #6

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

Similar topics

5
by: Lie | last post by:
Hi all, I have problem in getting selectedindex of multiple listbox selection in a datagrid. I have a listbox with multiple selection mode inside datagrid. In Edit mode, I need to get back all...
1
by: Karen Grube | last post by:
Hi! I'm using a standard server side ASP.Net listbox control on a web form. The page is basically various shades of green. The listbox itself has a pale green background and forest green text...
4
by: James Radke | last post by:
Hello, I am creating an owner draw listbox for a windows application. It is all working, except the performance is significantly slower than the standard listbox. Basically what I have done is...
9
by: Larry Serflaten | last post by:
I'm drawing my own inherited listbox, and I don't want the user to select any items, but I do want to allow them to scroll the listbox. When they click on an item, there is a flicker of the...
6
by: Max | last post by:
I need some control that basically acts as a listbox, but allows each item to take up more then one line. I've tried adding a new item and putting in a vbCrLf in there, but that just comes out as a...
2
by: dan heskett | last post by:
I am owner-drawing a listbox, in an attempt to create a nice list with some custom "fields" and text layout. Essentially it works, but I must be missing something big, conceptually, because I...
0
by: Mark Smith | last post by:
hi i use an ownerdraw method for coloring some items in the list different then the others. code: private void ListBoxDrawItem(object sender, DrawItemEventArgs e) { ListBox lst =...
3
by: CSharper | last post by:
Is it possible to selectivly change the color of an item in text. I saw ForeColor option, but it changes the color of all the items. If it is not possible, is there any other control list listbox...
2
EinToR
by: EinToR | last post by:
I'm trying to make a series of listboxes that filter the next listbox. Ex.: Listbox01: Toyota, Hundai Listbox02 (Toyota selected): Supra, Corola Listbox03: (Supra selected): Red, Black The...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
1
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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: 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...

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.