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

total a continuous form

158 100+
I have a continuous form with 5 columns (Qty, PartNum, Desc, ItemCost, TotalCos). At the bottom of the form i have a field labeled Invoice Total. Right now the Invoice Total is totaling everything in my tblInvoice. I need it to only total what rows that begin with the same InvoiceNumber. Here is what i have so far.

Expand|Select|Wrap|Line Numbers
  1. Private Sub UpdateInvoice()
  2.  
  3.   Dim rsItemMaster As ADODB.Recordset
  4.   Dim rsInvoice As ADODB.Recordset
  5.  
  6.   Set rsItemMaster = New ADODB.Recordset
  7.   Set rsInvoice = New ADODB.Recordset
  8.  
  9.   On Error GoTo ExitFunction:
  10.  
  11.   rsItemMaster.Open "tblItemMaster", CurrentProject.Connection, adOpenKeyset, adLockOptimistic, adCmdTable
  12.   rsItemMaster.MoveFirst
  13.   rsItemMaster.Find "Item='" & Me.cboPartNum & "'"
  14.  
  15.   Me.txtDescription.Value = rsItemMaster.Fields("Description").Value
  16.   Me.txtItemCost.Value = rsItemMaster.Fields("Cost").Value
  17.  
  18.   Me.txtTotalCost = Me.txtQty * Me.txtItemCost
  19.  
  20.   rsItemMaster.Close
  21.   Set rsItemMaster = Nothing
  22.  
  23.   rsInvoice.Open "tblInvoice", CurrentProject.Connection, adOpenKeyset, adLockOptimistic, adCmdTable
  24.  
  25.   'i think this is where the problem is  
  26.   rsInvoice.Filter = "[InvoiceNum] = " & Me.txtInvoiceNum
  27.  
  28.   rsInvoice.MoveFirst
  29.   Me.txtInvoiceTotal = 0
  30.  
  31.   Do While (rsInvoice.EOF = False)
  32.     Me.txtInvoiceTotal = Me.txtInvoiceTotal + rsInvoice.Fields("TotalCost").Value
  33.     rsInvoice.MoveNext
  34.     Me.Refresh
  35.   Loop
  36.  
  37.   If rsInvoice.EOF = True Then GoTo ExitFunction
  38.  
  39.   rsInvoice.Close
  40.   Set rsInvoice = Nothing
  41.  
  42.   Me.Refresh
  43.   Me.txtInvoiceNum = invoiceNumber
  44. ExitFunction:
  45.   'do nothing
  46.  
  47. End Sub

Right now it runs without errors, but not properly
Thanks in advance!
Sep 9 '08 #1
3 4634
Stewart Ross
2,545 Expert Mod 2GB
Oh dear Jollywg. VBA can be used to make things very unclear indeed, and this really is!

Why use this approach when you can simply place an unbound textbox control in your form's header or footer and set the control source of that textbox to

=Sum([TotalCost])

which will take account of any active filtering too?

In terms of your code you are defining a filter but not applying it. There are many other problems: use of me.refresh in the loop (completely unnecessary), not closing your recordset - I could go on. I'd review what you are trying to achieve and start again - doing away with code as far as possible by using much simpler functions such as Sum as mentioned.

-Stewart.
Sep 9 '08 #2
Jollywg
158 100+
Oh dear Jollywg. VBA can be used to make things very unclear indeed, and this really is!

Why use this approach when you can simply place an unbound textbox control in your form's header or footer and set the control source of that textbox to

=Sum([TotalCost])

which will take account of any active filtering too?

In terms of your code you are defining a filter but not applying it. There are many other problems: use of me.refresh in the loop (completely unnecessary), not closing your recordset - I could go on. I'd review what you are trying to achieve and start again - doing away with code as far as possible by using much simpler functions such as Sum as mentioned.

-Stewart.
if you only knew the half of it! haha. Although in my defense I'm writing code take chunks out putting chunks in and i'm fixing to go back and review it all and clean it up. This is an upgrade to a "database" that we currently have.

Thanks for all your help
matt
Sep 9 '08 #3
Jollywg
158 100+
Ok Stewart one more for ya,
whenever i create a new customer and click create invoice it comes up with the first record in the table and changes it's invoice number to the new customer's invoice. Clearly the form should be blank...how do i go about fixing this?

Thanks
Sep 9 '08 #4

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

Similar topics

3
by: Prakash Wadhwani | last post by:
Is there any EASY way to highlight a full row in a continuous form so that as i navigate up & down the table/continuous form using the arrow keys, the entire line (all fields) get highlighted ? ...
3
by: B | last post by:
I know there are several ways to speed up combo boxes and form loading. Most of the solutions leave rowsource of the combo box blank and set the rowsource to a saved query or an SQL with a where...
3
by: Mark | last post by:
Hi there, I have a subform, set as a continuous form. When a user selects a particular record in that subform, how can I make that particular record stand out (color or font change, size, etc) from...
3
by: Richard Hollenbeck | last post by:
I have the following query in my form's code: Private Function Get_Data(fieldNum As Integer) Dim strSQL As String Dim db As DAO.Database Dim rs As DAO.Recordset strSQL = "SELECT & "", "" & ...
4
by: Kathy | last post by:
What is the standard technique for handling the fields in the following scenario on a continuous form? Multiple Divisions. Each Division has multiple Buildings. Each Building has a Supervisor. ...
17
by: barkarlo | last post by:
I need help to make grand total time in continuous forms. to calculate total work time I use following formula =format(+1--nz();"short time"). but when I make grand total time in form footer (for...
3
by: virtualgreek | last post by:
Dear all, I have a scenario that is driving me nuts. (MS Access 2003) I have a form/subform (Continuous form) where it gets its data from tables Order and Order_Details. In the footer...
2
by: Steve | last post by:
I have a continuous form showing Product Code and Product Name. Product Code is five digits and is sequential. I have a textbox in the form header. What is the code to scroll the continuous form so...
8
by: Steffen Beck | last post by:
Hi NG I need some help with a problem on my forms. If I have 2 related tables, for instance companies and employees, and want to display all companies on a continuous form with their...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.