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

updating recordset after removing items from recordset list.

17
Hi,
I have a button that will add items to a list from another table and then total the cost of these items by clicking a total button. The problem I am having is that when I remove an item from the list it does not update the recordset so it continues to total the items even though the items are no longer there. Is there something wrong with my code? Help Please!!!! Here is the code I am using in my form.

Thanks in advance.

Private Sub cmdAdd_Click()
If Nz(TextQuantity.Value, "") = "" Then TextQuantity.Value = "1"
If Nz(cmbItem.Value, "") <> "" Then
Dim rs As DAO.Recordset
Set rs = DBEngine(0)(0).OpenRecordset("SELECT Cost FROM [Medical Supplies] WHERE Item = '" & removeApostrophes(cmbItem.Value) & "';")
If Not rs.EOF Then total = total + (CSng(rs!Cost) * CInt(TextQuantity.Value))
lstOrder.AddItem (TextQuantity.Value & "x " & cmbItem.Value)
End If

End Sub


Private Sub cmdremove_Click()
lstOrder.RemoveItem Index:=varItem

On Error GoTo 0

End Sub
Nov 23 '07 #1
9 2465
puppydogbuddy
1,923 Expert 1GB
Hi,
I have a button that will add items to a list from another table and then total the cost of these items by clicking a total button. The problem I am having is that when I remove an item from the list it does not update the recordset so it continues to total the items even though the items are no longer there. Is there something wrong with my code? Help Please!!!! Here is the code I am using in my form.

Thanks in advance.

Private Sub cmdAdd_Click()
If Nz(TextQuantity.Value, "") = "" Then TextQuantity.Value = "1"
If Nz(cmbItem.Value, "") <> "" Then
Dim rs As DAO.Recordset
Set rs = DBEngine(0)(0).OpenRecordset("SELECT Cost FROM [Medical Supplies] WHERE Item = '" & removeApostrophes(cmbItem.Value) & "';")
If Not rs.EOF Then total = total + (CSng(rs!Cost) * CInt(TextQuantity.Value))
lstOrder.AddItem (TextQuantity.Value & "x " & cmbItem.Value)
End If

End Sub


Private Sub cmdremove_Click()
lstOrder.RemoveItem Index:=varItem

On Error GoTo 0

End Sub
I don't see where anything is assigned to varitem in your code.
Nov 24 '07 #2
mdpems
17
I don't see where anything is assigned to varitem in your code.
That is probably my problem. This is the default remove item that is set up in Access. I am not sure what I need to put here code wise. I have tried putting index:=rs but this did not produce any results. Thanks for helping.
Nov 24 '07 #3
puppydogbuddy
1,923 Expert 1GB
That is probably my problem. This is the default remove item that is set up in Access. I am not sure what I need to put here code wise. I have tried putting index:=rs but this did not produce any results. Thanks for helping.
try this to remove one item:
lstOrder.RemoveItem lstOrder.ListIndex

or this to remove all items:
Do Until lstOrder.ListCount = 0
lstOrder.RemoveItem (0)
Loop
Nov 24 '07 #4
mdpems
17
try this to remove one item:
lstOrder.RemoveItem lstOrder.ListIndex

or this to remove all items:
Do Until lstOrder.ListCount = 0
lstOrder.RemoveItem (0)
Loop

I tried both of these. The first gives me a run time error stating invalid procedure call or argument. The second removes all items as stated but I can not retotal the items. The total still reflects as if all items were still there even though they are not. Thanks a bunch. I feel like I am close.
Nov 24 '07 #5
puppydogbuddy
1,923 Expert 1GB
I tried both of these. The first gives me a run time error stating invalid procedure call or argument. The second removes all items as stated but I can not retotal the items. The total still reflects as if all items were still there even though they are not. Thanks a bunch. I feel like I am close.

Here you go. Your original code was pretty close. According to this link the general syntax for removing a single item using the RemoveItem method is as shown below, but be aware that this method can only be used if the Listbox's row source property is set to value list
:
http://msdn2.microsoft.com/en-us/lib...ffice.11).aspx

General Syntax
------------------------
' Remove the list box item and set the return value
' to True, indicating success.
ctrlListBox.RemoveItem Index:=varItem
RemoveListItem = True

Based on the above your syntax would be:

lstOrder.RemoveItem Index:=varItem
RemoveListItem = True
Nov 24 '07 #6
mdpems
17
Here you go. Your original code was pretty close. According to this link the general syntax for removing a single item using the RemoveItem method is as shown below, but be aware that this method can only be used if the Listbox's row source property is set to value list
:
http://msdn2.microsoft.com/en-us/lib...ffice.11).aspx

General Syntax
------------------------
' Remove the list box item and set the return value
' to True, indicating success.
ctrlListBox.RemoveItem Index:=varItem
RemoveListItem = True

Based on the above your syntax would be:

lstOrder.RemoveItem Index:=varItem
RemoveListItem = True
Should this reset the total? For some reason no matter if I remove the item from the list or not the total still is reflecting as if the item is still there. Here is the code for my total button that I have. Sorry about the previous post. I did not get a response for several days so I thought that maybe my original post was not specific enough. Thanks for your help.

Private Sub cmdTotal_Click()
TextTotal.Value = Round(total, 2)

End Sub
Nov 24 '07 #7
puppydogbuddy
1,923 Expert 1GB
Should this reset the total? For some reason no matter if I remove the item from the list or not the total still is reflecting as if the item is still there. Here is the code for my total button that I have. Sorry about the previous post. I did not get a response for several days so I thought that maybe my original post was not specific enough. Thanks for your help.

Private Sub cmdTotal_Click()
TextTotal.Value = Round(total, 2)

End Sub
I am not sure, but here are a few things you can try:
1. try requerying or refreshing your listbox and see if that helps.
Private Sub cmdTotal_Click()
lstOrder.Requery
TextTotal.Value = Round(total, 2)

2. try recalcuating the total
total.Recalc
TextTotal.Value = Round(total, 2)

3. try requerying the recordset after the total is computed in the recordset
rs.requery
Nov 24 '07 #8
mdpems
17
I am not sure, but here are a few things you can try:
1. try requerying or refreshing your listbox and see if that helps.
Private Sub cmdTotal_Click()
lstOrder.Requery
TextTotal.Value = Round(total, 2)

2. try recalcuating the total
total.Recalc
TextTotal.Value = Round(total, 2)

3. try requerying the recordset after the total is computed in the recordset
rs.requery

None of that is working to requery the recordset. Is there anyway that I can reset the recordset and start over without reseting all the information in the form. What I am hoping to do is keep from having to reload the whole form.
Nov 24 '07 #9
puppydogbuddy
1,923 Expert 1GB
None of that is working to requery the recordset. Is there anyway that I can reset the recordset and start over without reseting all the information in the form. What I am hoping to do is keep from having to reload the whole form.
You can try the the .Edit and .Update methods of updating the recordset. However, I believe requerying the listbox should have worked. If the requery is not working for you then the problem is probably where I suggested that you place the code, try placing the requery after the end of your main recordset loop and see if that helps.

This link has several free downloadable databases that contain listboxes that have calculations.that are requeried. Hope this helps.

http://www.cse.dmu.ac.uk/~mcspence/E...0databases.htm
Nov 26 '07 #10

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

Similar topics

1
by: Roy Adams | last post by:
Hi everyone I'm trying to build a shopping cart app using a db the part I'm stuck on is the fact that, if someone adds a product that they have previously added to the cart. I've got it set up to...
4
by: Lyn | last post by:
Hi, This question may seem a bit academic... To learn more about Access VBA, I have been enumerating the properties of various form controls. This was mostly successful and I have learned a lot...
3
by: Jeremy Owens-Boggs | last post by:
We are trying to implement a dual list box selection where you have two list boxes, You highlight items in the right side list box, click a button and this moves those items over to the left hand...
7
by: =?Utf-8?B?Sm9lbCBNZXJr?= | last post by:
I have created a custom class with both value type members and reference type members. I then have another custom class which inherits from a generic list of my first class. This custom listneeds...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
jinu1996
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...
0
agi2029
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,...

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.