I have four listboxes on my form. When I add a new record, I run the following code to clear list box items... - Public Function ClearAll()
-
'This function clears ALL selected fields in the [BillExpUpdate] form's workspace.
-
Dim var As Variant
-
-
For Each var In Forms![BillExpUpdate].[lst1st_Bills].ItemsSelected
-
Forms![BillExpUpdate].[lst1st_Bills].Selected(var) = False
-
Next
-
For Each var In Forms![BillExpUpdate].[lst1st_Exp].ItemsSelected
-
Forms![BillExpUpdate].[lst1st_Exp].Selected(var) = False
-
Next
-
For Each var In Forms![BillExpUpdate].[lst15th_Bills].ItemsSelected
-
Forms![BillExpUpdate].[lst15th_Bills].Selected(var) = False
-
Next
-
For Each var In Forms![BillExpUpdate].[lst15th_Exp].ItemsSelected
-
Forms![BillExpUpdate].[lst15th_Exp].Selected(var) = False
-
Next
-
End Function
-
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.
5 4723
I have four listboxes on my form. When I add a new record, I run the following code to clear list box items... - Public Function ClearAll()
-
'This function clears ALL selected fields in the [BillExpUpdate] form's workspace.
-
Dim var As Variant
-
-
For Each var In Forms![BillExpUpdate].[lst1st_Bills].ItemsSelected
-
Forms![BillExpUpdate].[lst1st_Bills].Selected(var) = False
-
Next
-
For Each var In Forms![BillExpUpdate].[lst1st_Exp].ItemsSelected
-
Forms![BillExpUpdate].[lst1st_Exp].Selected(var) = False
-
Next
-
For Each var In Forms![BillExpUpdate].[lst15th_Bills].ItemsSelected
-
Forms![BillExpUpdate].[lst15th_Bills].Selected(var) = False
-
Next
-
For Each var In Forms![BillExpUpdate].[lst15th_Exp].ItemsSelected
-
Forms![BillExpUpdate].[lst15th_Exp].Selected(var) = False
-
Next
-
End Function
-
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. - sub ClearListBoxes()
-
dim x, ctl as control
-
-
for each ctl in me.controls
-
if ctl.controltype=aclistbox then
-
with me(ctl.name)
-
for each x in .itemsselected
-
.selected(x)=false
-
next
-
end with
-
end if
-
next
-
end sub
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. - sub ClearListBoxes()
-
dim x, ctl as control
-
-
for each ctl in me.controls
-
if ctl.controltype=aclistbox then
-
with me(ctl.name)
-
for each x in .itemsselected
-
.selected(x)=false
-
next
-
end with
-
end if
-
next
-
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. - Private Sub txtBill_Name_DblClick(Cancel As Integer)
-
On Error GoTo Err_txtBill_Name_DblClick
-
-
'Add/Saves New record
-
DoCmd.GoToRecord , , acNewRec
-
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
-
-
Exit_txtBill_Name_DblClick:
-
ClearList
-
ScanBox
-
Exit Sub
-
-
Err_txtBill_Name_DblClick:
-
MsgBox Err.Description
-
Resume Exit_txtBill_Name_DblClick
-
End Sub
Again, any help would be greatly appreciated...
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. - Private Sub txtBill_Name_DblClick(Cancel As Integer)
-
On Error GoTo Err_txtBill_Name_DblClick
-
-
'Add/Saves New record
-
DoCmd.GoToRecord , , acNewRec
-
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
-
-
Exit_txtBill_Name_DblClick:
-
ClearList
-
ScanBox
-
Exit Sub
-
-
Err_txtBill_Name_DblClick:
-
MsgBox Err.Description
-
Resume Exit_txtBill_Name_DblClick
-
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.DoMenuIte m acFormBar, acRecordsMenu, 5, , acMenuVer70
you should use:
DoCmd.RunComman d acCmdSaveRecord
PDB, your point about the DoCmd.DoMenuIte m 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.RunComman d 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)>
PDB, your point about the DoCmd.DoMenuIte m 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.RunComman d 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.RunComman d acSaveRecord.
On the other hand, the OP (not me) stated that he tried the DoCmd.DoMenuIte m 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.DoMenuIte m syntax was outdated, although still allowed to be used.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 selected items of that listbox and display
it.
can anyone help?
Thanks
|
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 and a forest green border. However,
when you move the cursor from one item to the next within the listbox or you
click on an item in the listbox to select it, the background turns to the
standard windows dark blue with white letters. Well, that...
|
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 added two new properties (full
source below):
ChangeBackgroundMember = a bound data field which contains a boolean as
to whether this record should get a special background color
ChangeBackgroundColor = the color to use when the above...
|
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 previously
selected item and the new selected item. Even though I don't
show anything selected, the default behaviour wants to redraw
those items.
What can I do to stop the user click from selecting an item in
the list?
|
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 box on the
same line. Is there some way of making the listbox show multiple lines
for each item, or is there another control (3rd party maybe) that will
let me do this?
| |
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 get all kinds of screen artifacts and weirdness.
My general goal is: list item with a few areas for text, every other item
shaded a light color for readability, font color changes with selection. The
listbox is populated with custom structurs...
|
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 = (ListBox)sender;
|
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 where we can
see more than one item and change the color during run time.
Thanks.
|
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 DataSource is an XML file simnilar to this:
|
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: 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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |