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

Running Sum (Line no.) in Form

How can I put a Running Sum (Line No.) in a form, as in the case of Report?

(Primary key i.e. Auto generate Number) does not solve my problem, as in my form, filter is used to display only selected records. I want to generate serial no. (running sum) at the time of entering new records, based on my filtered records in table.

Your help is solicited.

Thanks in advance.
Sep 22 '07 #1
21 3205
NeoPa
32,556 Expert Mod 16PB
The short answer is that you can't. There may be clever ways around this but in principle it doesn't work.
In your position I would capture the BeforeUpdate event and add a number in after checking the max number used in the table so far (DMax() will give you the value you need - plus one of course).
Sep 22 '07 #2
FishVal
2,653 Expert 2GB
Hi, there.

So basically you want to have a textbox/label with RecordNumber as in navigation bar. Am I right?
Sep 22 '07 #3
Hi, there.

So basically you want to have a textbox/label with RecordNumber as in navigation bar. Am I right?
Yes I want a text box / label with a record no.
Sep 24 '07 #4
The short answer is that you can't. There may be clever ways around this but in principle it doesn't work.
In your position I would capture the BeforeUpdate event and add a number in after checking the max number used in the table so far (DMax() will give you the value you need - plus one of course).

Kindly give me example how to use DMAX with an increment.
Sep 24 '07 #5
FishVal
2,653 Expert 2GB
Yes I want a text box / label with a record no.
Something like this.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.  
  3.     Dim varRecordNumber As Variant
  4.  
  5.     If Me.NewRecord Then
  6.         varRecordNumber = "*"
  7.     Else
  8.         varRecordNumber = Me.Recordset.AbsolutePosition + 1
  9.     End If
  10.     Me.txtRecordNo = varRecordNumber 
  11.  
  12. End Sub
  13.  
Sep 24 '07 #6
NeoPa
32,556 Expert Mod 16PB
Kindly give me example how to use DMAX with an increment.
Expand|Select|Wrap|Line Numbers
  1. Dim lngRecNo as Long
  2.  
  3. lngRecNo = Nz(DMax("[RecordNumber]", "[YourTable]"), 0) + 1
Sep 24 '07 #7
Expand|Select|Wrap|Line Numbers
  1. Dim lngRecNo as Long
  2.  
  3. lngRecNo = Nz(DMax("[RecordNumber]", "[YourTable]"), 0) + 1
Thanks for your reply. Now, my program has slightly been changed. Now, I want automatically increment value in database, based on group(field). Is it possible? You can evident from the following table:
Expand|Select|Wrap|Line Numbers
  1. ID        Item             BillNo             Qty 
  2. 01       Aluminium     RSA-01          100
  3. 02       Aluminium     U/06007           50
  4. 01       Scrap            2003                50
  5. 01       Zinc              24/07-08           33
  6. 03       Aluminium     24242-AL         22
  7. 02       Scrap            AB-24            241
I am sure, you can understand what I want in the program.

Awaiting for reply.

Thanks in advance.
Sep 25 '07 #8
NeoPa
32,556 Expert Mod 16PB
...
I am sure, you can understand what I want in the program.
...
Seems like misplaced confidence I'm afraid.
None of that made any sense to me at all :(
Sep 25 '07 #9
FishVal
2,653 Expert 2GB
Pass criteria to DMax function
Expand|Select|Wrap|Line Numbers
  1. lngRecNo = Nz(DMax("[RecordNumber]", "[YourTable]","[Item Name]='Aluminium'"), 0) + 1
  2.  
Sep 25 '07 #10
NeoPa
32,556 Expert Mod 16PB
Nice one Fish.
If that was the question that's a good answer (Even got the SQL quote chars right) :)
Sep 25 '07 #11
FishVal
2,653 Expert 2GB
Nice one Fish.
If that was the question that's a good answer (Even got the SQL quote chars right) :)
Glad it worked for you. Welcome to TSDN.

:-P

Nevermind. Just a .... joke [?]
Sep 25 '07 #12
NeoPa
32,556 Expert Mod 16PB
:D
.
Sep 25 '07 #13
I am still confused. I have passed following code in Before Update() event but it did not work, in the way I want.
Expand|Select|Wrap|Line Numbers
  1. Dim lngRecNo As Long
  2. lngRecNo = Nz(DMax("[LineNumber]", "[Receipt]", "[ItemID]=1"), 0) + 1
Please let me know where this code to be written whether in

a) Before Upadate() - as I wrote.
b) Before Insert in Form window
c) Deafult value of control

Also, I am afraid if another item is selected (Besides Aluminium), how it will work. For each ItemID, a separate code is required.

Please enlighten me.

Thanks in advance.
Pass criteria to DMax function
Expand|Select|Wrap|Line Numbers
  1. lngRecNo = Nz(DMax("[RecordNumber]", "[YourTable]","[Item Name]='Aluminium'"), 0) + 1
  2.  
Sep 26 '07 #14
FishVal
2,653 Expert 2GB
Hi, there.

Sure filter being passed to DMax() may and should be dynamic.

In presumption your form control bound to [ItemID] table field has name [ItemID].

In BeforeUpdate event handler.
Expand|Select|Wrap|Line Numbers
  1. Dim lngRecNo As Long
  2. lngRecNo = Nz(DMax("[LineNumber]", "[Receipt]", "[ItemID]=" & Me![ItemID]), 0) + 1
  3.  
Sep 26 '07 #15
NeoPa
32,556 Expert Mod 16PB
Let us know how you get on with this Sanjay.
Notice that the quotes (') are not required in this version as the [ItemID] is a numeric field.
Sep 26 '07 #16
Not working this command in the before update event. I have tried with text box but not getting value increased & showing "0"

I have gone though various articles about DMAX() but fail to find any solution.

Any solution ??????
Hi, there.

Sure filter being passed to DMax() may and should be dynamic.

In presumption your form control bound to [ItemID] table field has name [ItemID].

In BeforeUpdate event handler.
Expand|Select|Wrap|Line Numbers
  1. Dim lngRecNo As Long
  2. lngRecNo = Nz(DMax("[LineNumber]", "[Receipt]", "[ItemID]=" & Me![ItemID]), 0) + 1
  3.  
Sep 27 '07 #17
NeoPa
32,556 Expert Mod 16PB
Sanjay,

Firstly please don't shout (all uppercase) and waste space on the page. This is annoying for people trying to read it (and ultimately trying to help you out).

Secondly, if you would like us to understand what your problem is then it would be a good idea to share your code with us.
Sep 27 '07 #18
As desired, I am giving below the code of the form, which will help you in understanding the exact requirement, which I am facing in auto increment based on criteria.
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Private blnConfirmUndo As Boolean
  3. Private blnConfirmDelete As Boolean
  4. Private blnSaveButton As Boolean
  5. Private lngDeleted As Long
  6.  
  7. Private Sub cmdAdd_Click()
  8.     Me.AllowAdditions = True
  9.     DoCmd.GoToRecord , , acNewRec
  10.     Me.ItemID.SetFocus
  11. End Sub
  12.  
  13. Private Sub cmdDel_Click()
  14.     blnConfirmDelete = False
  15.     ResponseMSG = MsgBox(Prompt:="You are permanently deleting this record, are you sure?", Buttons:=vbYesNo)
  16.     If ResponseMSG = vbYes Then
  17.         DoCmd.RunCommand acCmdDeleteRecord
  18.         Me.Refresh
  19.     End If
  20.     blnConfirmDelete = True
  21. End Sub
  22.  
  23. Private Sub cmdSave_Click()
  24. Dim dbs As Database
  25. Dim rcd As Recordset
  26. Set dbs = CurrentDb
  27. Set rcd = dbs.OpenRecordset("Receipt")
  28.     If IsNull(Item) Then
  29.         MsgBox ("Item is missing"), vbCritical
  30.         DoCmd.GoToControl ("Item")
  31.         Exit Sub
  32.     End If
  33.     If IsNull(Quantity) Then
  34.         MsgBox ("Quantity is missing"), vbCritical
  35.         DoCmd.GoToControl ("Quantity")
  36.         Exit Sub
  37.     End If
  38.     If IsNull(BillNumber) Then
  39.         MsgBox ("Bill Number is missing"), vbCritical
  40.         DoCmd.GoToControl ("BillNumber")
  41.         Exit Sub
  42.     End If
  43.     If IsNull(BillDate) Then
  44.         MsgBox ("Bill Date is missing"), vbCritical
  45.         DoCmd.GoToControl ("BillDate")
  46.         Exit Sub
  47.     End If
  48.     If IsNull(ImporterID) Then
  49.         MsgBox ("Party Name is missing"), vbCritical
  50.         DoCmd.GoToControl ("Importerid")
  51.         Exit Sub
  52.     End If
  53.     blnSaveButton = True
  54.     DoCmd.RunCommand acCmdSaveRecord
  55.     blnSaveButton = False
  56.     Me.Receive_SubForm.Requery
  57.     DoCmd.OpenQuery ("Update Receipt")
  58. End Sub
  59.  
  60. Private Sub Exit_Click()
  61. DoCmd.Quit
  62. End Sub
  63.  
  64. Private Sub Form_BeforeUpdate(Cancel As Integer)
  65. Dim lngRecNo As Long
  66. lngRecNo = Nz(DMax("[LineNumber]", "[Receipt]", "[ItemID]=" & Me![ItemID]), 0) + 1
  67. End Sub
  68.  
  69. Private Sub ItemID_AfterUpdate()
  70.     Me.cmdSave.Enabled = True
  71. End Sub
  72.  
  73. Private Sub Receive_SubForm_Enter()
  74.     If IsNull(Me![ItemID]) Then
  75.         MsgBox "You must enter details before viewing records"
  76.         Me.ItemID.SetFocus
  77.     End If
  78. Me.Refresh
  79. End Sub
  80.  
  81. Private Sub Form_AfterUpdate()
  82.     Me.AllowAdditions = False
  83.     Form_Current
  84. End Sub
  85.  
  86. Private Sub Form_Current()      
  87.     If IsNull(Me![ItemID]) Then
  88.         DoCmd.GoToControl "ItemID"
  89.     End If
  90.  
  91.     Me.ItemID.SetFocus
  92.  
  93.     Dim blnNewRecord As Boolean
  94.     blnNewRecord = Me.NewRecord
  95.     Me.AllowAdditions = blnNewRecord
  96.     'Me.AllowAdditions = False
  97.     Me.cmdAdd.Enabled = Not blnNewRecord
  98.     Me.cmdDel.Enabled = Not blnNewRecord
  99.  
  100.     Dim blnDirty As Boolean
  101.     blnDirty = Me.Dirty
  102.     Me.cmdSave.Enabled = blnDirty
  103. End Sub
  104.  
  105. Private Sub Form_Dirty(Cancel As Integer)
  106.     Me.cmdSave.Enabled = True
  107. End Sub
  108.  
  109. Private Sub Form_Open(Cancel As Integer)
  110.     DoCmd.SetWarnings Off
  111.     DoCmd.Maximize
  112.     blnConfirmUndo = True
  113.     blnConfirmDelete = True
  114. End Sub
  115.  
  116. Private Sub Head_DblClick(Cancel As Integer)
  117. DoCmd.OpenForm ("Receivehd"), , , , , acDialog
  118. Me![Head].Requery
  119. End Sub
  120.  
  121. Private Sub ImporterID_DblClick(Cancel As Integer)
  122. DoCmd.OpenForm ("Importer"), , , , , acDialog
  123. Me![ImporterID].Requery
  124. End Sub
  125.  
  126. Private Sub ImporterID_NotInList(NewData As String, Response As Integer)
  127. MsgBox "This Party is not in list.Double Click to Add ", vbInformation
  128. End Sub
  129.  
  130. Private Sub ItemID_DblClick(Cancel As Integer)
  131. DoCmd.OpenForm ("Item"), , , , , acDialog
  132. Me![ItemID].Requery
  133. End Sub
  134.  
  135.  
  136.  
  137. Private Sub ItemID_NotInList(NewData As String, Response As Integer)
  138. MsgBox "This item is not in list.Double Click to Add ", vbInformation
  139. End Sub
  140.  
  141. Private Sub Head_NotInList(NewData As String, Response As Integer)
  142. MsgBox "This item is not in list.Double Click to Add ", vbInformation
  143. End Sub
  144.  
  145. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  146. Select Case KeyCode
  147.     Case 33, 34
  148.     KeyCode = 0
  149. End Select
  150. End Sub
  151.  
  152. Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
  153. Select Case KeyCode
  154.     Case 33, 34
  155.     KeyCode = 0
  156. End Select
  157. End Sub
Sanjay,

Firstly please don't shout (all uppercase) and waste space on the page. This is annoying for people trying to read it (and ultimately trying to help you out).

Secondly, if you would like us to understand what your problem is then it would be a good idea to share your code with us.
Sep 28 '07 #19
FishVal
2,653 Expert 2GB
As desired, I am giving below the code of the form, which will help you in understanding the exact requirement, which I am facing in auto increment based on criteria.


Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim lngRecNo As Long
lngRecNo = Nz(DMax("[LineNumber]", "[Receipt]", "[ItemID]=" & Me![ItemID]), 0) + 1
End Sub
It will be a good idea to save calculated number to the table as well.
The easiest way to do it is to add to the form a control bound to [LineNumber] table field. Let us say the control is Textbox named [LineNumber].

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.     Me![LineNumber] = Nz(DMax("[LineNumber]", "[Receipt]", _
  3.         "[ItemID]=" & Me![ItemID]), 0) + 1
  4. End Sub
  5.  
Sep 28 '07 #20
You are great!

Thanks a lot. Now, I am able to do the job, what I required.

Thanking you once again.





It will be a good idea to save calculated number to the table as well.
The easiest way to do it is to add to the form a control bound to [LineNumber] table field. Let us say the control is Textbox named [LineNumber].

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.     Me![LineNumber] = Nz(DMax("[LineNumber]", "[Receipt]", _
  3.         "[ItemID]=" & Me![ItemID]), 0) + 1
  4. End Sub
  5.  
Sep 28 '07 #21
FishVal
2,653 Expert 2GB
Glad it worked for you. Good luck.

Best regards,
Fish
Sep 28 '07 #22

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

Similar topics

7
by: Christopher Brandsdal | last post by:
Hi! I have a problem running my code on 2000 server and iis5.0. The code runs perfectly on my localhost (xp iis5.1) but when i run it on 2000 server iis5.0 I get this error: ...
4
by: Randy | last post by:
Hi, ok, I found a way to connect to a running instance of an (external) Internet Explorer and access - for example - the html source. That works fine! But now I have running application with...
3
by: ° ^F®ęâK^ ° | last post by:
Blank hi there, I just want to explain my problem. There is an application which is coded by me running. It is an vb.net application having user controls windows forms and something like visual...
1
by: Anonieko | last post by:
Query: How to display progress bar for long running page Answer: Yet another solution. REFERENCE: http://www.eggheadcafe.com/articles/20050108.asp My only regret is that when click the...
1
by: muchexie | last post by:
i have two scripts that are not running to reset a password that has been forgotten and the other to change old password. here are the scripts. change_passwd.php <? ...
2
by: muchexie | last post by:
i have two scripts that are not running to reset a password that has been forgotten and the other to change old password. here are the scripts. change_passwd.php session_start();...
3
by: Phil Stanton | last post by:
I have a number of queries which use code for the output of 1 or more fields. For example Address:GetAddress(AddressID, True, 60) Address ID Points to an Address in a table - Address Line1, Line...
51
by: Ojas | last post by:
Hi!, I just out of curiosity want to know how top detect the client side application under which the script is getting run. I mean to ask the how to know whether the script is running under...
1
by: kulak | last post by:
As my search for a solution to this problem gave no useful results, I decided to post it here. I appreciate any help in this regard. I'm having a minor, yet annoying, problem: When opening a...
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
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?
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
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
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...
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.