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

code Receiptno increment not working.........

i have data entry form entry field [Receiptno] required number 1 to 100 increment by 1 in each entry auto started from 1.

The code below not working........
Expand|Select|Wrap|Line Numbers
  1. Private Sub ReceiptNo_AfterUpdate()
  2. If Me.NewRecord = True Then
  3.     ReceiptNo = Nz(DMax("[receiptno]", "[receiptno]"), 0)
  4.     Me.ReceiptNo = ReceiptNo + 1
  5.     End If
  6. End Sub
plz help....
Attached Images
File Type: jpg form.jpg (27.7 KB, 134 views)
Feb 4 '15 #1

✓ answered by twinnyfo

2015sandeep,

Welcome to Bytes!

First, please use Code Tags when posting your code.

What is the name of the Table that holds the field "ReceiptNo"? This should be the second argument in your DMax() Function. You can also streamline your Code:

Expand|Select|Wrap|Line Numbers
  1. If Me.NewRecord = Then Me.ReceiptNo = Nz(DMax("[ReceiptNo]", "[tblName]"), 0) + 1
However, the big problem I see is what you will do when you exceed 100 records? Why not just use an AutoNumber which will auto increment all your records each time a new one is made? This would be a more standard methodology, unless, there is some particular reason that the ReceiptNo must reset at 100....

6 1306
twinnyfo
3,653 Expert Mod 2GB
2015sandeep,

Welcome to Bytes!

First, please use Code Tags when posting your code.

What is the name of the Table that holds the field "ReceiptNo"? This should be the second argument in your DMax() Function. You can also streamline your Code:

Expand|Select|Wrap|Line Numbers
  1. If Me.NewRecord = Then Me.ReceiptNo = Nz(DMax("[ReceiptNo]", "[tblName]"), 0) + 1
However, the big problem I see is what you will do when you exceed 100 records? Why not just use an AutoNumber which will auto increment all your records each time a new one is made? This would be a more standard methodology, unless, there is some particular reason that the ReceiptNo must reset at 100....
Feb 4 '15 #2
Expand|Select|Wrap|Line Numbers
  1. Private Sub Save_Click()
  2. If IsNull(Me![ReceiptNo]) Then
  3. Me.[ReceiptNo] = Format(Nz(DMax("receiptno", "compiled", "bookno]='" & Me.BookNo & "'"), 0) + 1, "000")
  4. End If
  5. End Sub
this code not working what to do for increment receiptno???? plz help
Feb 16 '15 #3
MikeTheBike
639 Expert 512MB
Hi

You need an opening square bracket to match the closing bracket, ie. this
Expand|Select|Wrap|Line Numbers
  1. Me.[ReceiptNo] = Format(Nz(DMax("receiptno", "compiled", "bookno]='" & Me.BookNo & "'"), 0) + 1, "000")
should be like this
Expand|Select|Wrap|Line Numbers
  1. Me.[ReceiptNo] = Format(Nz(DMax("receiptno", "compiled", "[bookno]='" & Me.BookNo & "'"), 0) + 1, "000")
I assume that receiptno and bookno are both Text fields.


MTB
Feb 16 '15 #4
i have tabled named compiled, and fields bookno, receiptno
data needed like...
bookno receiptno
1230 1
1230 2
1231 1
1231 2

form created but code not working...
Expand|Select|Wrap|Line Numbers
  1. Private Sub ReceiptNo_BeforeUpdate(Cancel As Integer)
  2. If IsNull(Me.NewRecord) Then
  3. Me!ReceiptNo = Nz(DMax("receiptno", "compiled", "bookno='" & BookNo), 0) + 1
  4. End If
  5. End Sub
Mar 22 '15 #5
MikeTheBike
639 Expert 512MB
Hi

I think pehaps you mean this
Expand|Select|Wrap|Line Numbers
  1. Private Sub ReceiptNo_BeforeUpdate(Cancel As Integer)
  2. If IsNull(Me!ReceiptNo) Then
  3. Me!ReceiptNo = Nz(DMax("receiptno", "compiled", "bookno='" & BookNo), 0) + 1
  4. End If
  5. End Sub
However this would also do it (I thiink?)
Expand|Select|Wrap|Line Numbers
  1. Private Sub ReceiptNo_BeforeUpdate(Cancel As Integer)
  2. If Me.NewRecord Then
  3. Me!ReceiptNo = Nz(DMax("receiptno", "compiled", "bookno='" & BookNo), 0) + 1
  4. End If
  5. End Sub
I think this would be the more logical way because if ReceiptNo is Null and it is not a new record then something is wrong!?

MTB
Mar 23 '15 #6
jforbes
1,107 Expert 1GB
I think this line should either be:
Expand|Select|Wrap|Line Numbers
  1. Me!ReceiptNo = Nz(DMax("receiptno", "compiled", "bookno=" & BookNo), 0) + 1
or
Expand|Select|Wrap|Line Numbers
  1. Me!ReceiptNo = Nz(DMax("receiptno", "compiled", "bookno='" & BookNo & "'"), 0) + 1
depending whether or not BookNo is numeric.
Mar 23 '15 #7

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

Similar topics

3
by: Lenn | last post by:
Hello, I have the following example of AsyncCallback from a C# book which I wanted to implement in my project: //Class with AsyncDelegate public class AsyncProcess { public AsyncProcess() {
4
by: jason | last post by:
i am writing some simple web forms with VB.NET as the code-behind language. the code-behind files import a C# class library namespace from a .dll which is in the references list. however,...
4
by: candexis | last post by:
Hi!!!!!!! could you please tell me why this code in not working properly, the thing is that when I read one string after another, the second one is not read, and I don't know why, I am using...
2
by: micatcat | last post by:
Hello, I need help with writing up a code to increment a text field to read 2007-1, 2007-2, etc... I have a submit button that should increment the field when the user clicks on it. Thank you.
31
by: ajos | last post by:
hi frnds, i have a form,which has 2 input text boxes, the values are entering the text boxes,when i leave the 2 text boxes blank and hit submit a java script gives the message that the 2 fields are...
3
by: Mohd Baseerul Mubeen | last post by:
Hey! I am a beginner Can anybody help me with the code behind for working with responsexml
0
by: George2 | last post by:
Hello everyone, From the definition of working set, it is a subset of virtual pages resident in physical memory -- from book Windows Internals. It means working set could not be larger than...
5
by: mukeshrasm | last post by:
Hi I am using AJAX to display the value in selection/list box. this code is working fine in Firefox Mozila browser but it is not working in Internet Explorer so please tell me how this will work...
11
by: wassimdaccache | last post by:
Dear friends I am working on access 2007 sp2. I do have a database(accdb) i converted it to accde. While I am opening the converted database the VBA code is not working. For example...
2
blackgoat
by: blackgoat | last post by:
Hi! Pls help! My code is not working! Pls tell me whats wrong with it... it returns value 1 in all cases!! %dbase = { apple => "fruit", brinjal => "vegetable" , ...
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: 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
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: 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...

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.