473,387 Members | 1,492 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.

Incrementing Number/Leading Zeros

Hey All,

I know this has been addressed in a few different conversations but
none are exactly what I am trying to do, bear with me I am an access
Newbie.

Basically I have a form that assigns Run Numbers to each record (EMS
agency, each record is a Run Number, versus like a PO number or Work
Order..).

Right now I have a field which I call "displayedRunNumber" stored in a
table as a number. The default value in the table is 0.

In the form where the counter is viewed I have a before update code of:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.NewRecord Then
Me!displayedRunNumber = Nz(DMax("displayedRunNumber", "fields"),
1000) + 1

End If

End Sub

This basically starts displayedRunNumber at 1001 for the first record
in the form. The code also works nicely because the number isnt
generated until the user clicks a Save button I have on the form to
ensure he/she fills in all the information before he gets the Run
Number he/she needs to finish a report.

**Here's the problem. instead of 1001, I need the starting number to be
0001 and increment from there. I thought it would be OK my way, but the
law says it has to be 0001. I still want the same functionality as far
as the number generating after the record is saved. The problem is the
leading zeros, I guess the format of the displayedRunNumber has to text
I guess.

Also I would prefer not to force the number into looking the way I want
it because I need to be able to search for say 0018 and find it.

Any help would be SO GREATLY appreciated!! I am very new at all this so
if you have code or suggestions please tell me where it is supposed to
go as people often reference code and I have no idea where it goes.

Thanks so much everyone,

Brad G.

Jul 31 '06 #1
3 3264
<br***********@gmail.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
Hey All,

I know this has been addressed in a few different conversations but
none are exactly what I am trying to do, bear with me I am an access
Newbie.

Basically I have a form that assigns Run Numbers to each record (EMS
agency, each record is a Run Number, versus like a PO number or Work
Order..).

Right now I have a field which I call "displayedRunNumber" stored in a
table as a number. The default value in the table is 0.

In the form where the counter is viewed I have a before update code of:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.NewRecord Then
Me!displayedRunNumber = Nz(DMax("displayedRunNumber", "fields"),
1000) + 1

End If

End Sub

This basically starts displayedRunNumber at 1001 for the first record
in the form. The code also works nicely because the number isnt
generated until the user clicks a Save button I have on the form to
ensure he/she fills in all the information before he gets the Run
Number he/she needs to finish a report.

**Here's the problem. instead of 1001, I need the starting number to be
0001 and increment from there. I thought it would be OK my way, but the
law says it has to be 0001. I still want the same functionality as far
as the number generating after the record is saved. The problem is the
leading zeros, I guess the format of the displayedRunNumber has to text
I guess.

Also I would prefer not to force the number into looking the way I want
it because I need to be able to search for say 0018 and find it.

Any help would be SO GREATLY appreciated!! I am very new at all this so
if you have code or suggestions please tell me where it is supposed to
go as people often reference code and I have no idea where it goes.

Thanks so much everyone,

Brad G.
Why not omit the 1000+ portion? Just let the the counter use DMax + 1.
Then use the following expression as the Source:

=Format([displayedRunNumber], '00000')

Fred Zuckerman


Jul 31 '06 #2
Fred,

Thanks for the help...

I changed the before update field of the form to:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.NewRecord Then
Me!displayedRunNumber = (DMax("displayedRunNumber", "fields")) + 1

End If

End Sub

I changed the Control Source of the text box I'm using to display the
number in the form to:

=Format([displayedRunNumber],'00000')

When I run the form I get #Error in the text box where I am supposed to
see the Run Number?

Any ideas whats going on?

Thanks
Fred Zuckerman wrote:
<br***********@gmail.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
Hey All,

I know this has been addressed in a few different conversations but
none are exactly what I am trying to do, bear with me I am an access
Newbie.

Basically I have a form that assigns Run Numbers to each record (EMS
agency, each record is a Run Number, versus like a PO number or Work
Order..).

Right now I have a field which I call "displayedRunNumber" stored in a
table as a number. The default value in the table is 0.

In the form where the counter is viewed I have a before update code of:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.NewRecord Then
Me!displayedRunNumber = Nz(DMax("displayedRunNumber", "fields"),
1000) + 1

End If

End Sub

This basically starts displayedRunNumber at 1001 for the first record
in the form. The code also works nicely because the number isnt
generated until the user clicks a Save button I have on the form to
ensure he/she fills in all the information before he gets the Run
Number he/she needs to finish a report.

**Here's the problem. instead of 1001, I need the starting number to be
0001 and increment from there. I thought it would be OK my way, but the
law says it has to be 0001. I still want the same functionality as far
as the number generating after the record is saved. The problem is the
leading zeros, I guess the format of the displayedRunNumber has to text
I guess.

Also I would prefer not to force the number into looking the way I want
it because I need to be able to search for say 0018 and find it.

Any help would be SO GREATLY appreciated!! I am very new at all this so
if you have code or suggestions please tell me where it is supposed to
go as people often reference code and I have no idea where it goes.

Thanks so much everyone,

Brad G.

Why not omit the 1000+ portion? Just let the the counter use DMax + 1.
Then use the following expression as the Source:

=Format([displayedRunNumber], '00000')

Fred Zuckerman
Aug 1 '06 #3
Brad,
(I'll top-post because you did. I prefer top-posting, but this group prefers
bottom-posting)

1. Is the name of the control [displayedRunNumber] ? The fieldname of the
table data and the name of the form display control should be different.

2. I usually use the Default property for the DMax() function, not the
Before Update event.

Fred

<br***********@gmail.comwrote in message
news:11*********************@b28g2000cwb.googlegro ups.com...
Fred,

Thanks for the help...

I changed the before update field of the form to:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.NewRecord Then
Me!displayedRunNumber = (DMax("displayedRunNumber", "fields")) + 1

End If

End Sub

I changed the Control Source of the text box I'm using to display the
number in the form to:

=Format([displayedRunNumber],'00000')

When I run the form I get #Error in the text box where I am supposed to
see the Run Number?

Any ideas whats going on?

Thanks
Fred Zuckerman wrote:
<br***********@gmail.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
Hey All,
>
I know this has been addressed in a few different conversations but
none are exactly what I am trying to do, bear with me I am an access
Newbie.
>
Basically I have a form that assigns Run Numbers to each record (EMS
agency, each record is a Run Number, versus like a PO number or Work
Order..).
>
Right now I have a field which I call "displayedRunNumber" stored in a
table as a number. The default value in the table is 0.
>
In the form where the counter is viewed I have a before update code
of:
>
Private Sub Form_BeforeUpdate(Cancel As Integer)
>
If Me.NewRecord Then
Me!displayedRunNumber = Nz(DMax("displayedRunNumber", "fields"),
1000) + 1
>
End If
>
End Sub
>
This basically starts displayedRunNumber at 1001 for the first record
in the form. The code also works nicely because the number isnt
generated until the user clicks a Save button I have on the form to
ensure he/she fills in all the information before he gets the Run
Number he/she needs to finish a report.
>
**Here's the problem. instead of 1001, I need the starting number to
be
0001 and increment from there. I thought it would be OK my way, but
the
law says it has to be 0001. I still want the same functionality as far
as the number generating after the record is saved. The problem is the
leading zeros, I guess the format of the displayedRunNumber has to
text
I guess.
>
Also I would prefer not to force the number into looking the way I
want
it because I need to be able to search for say 0018 and find it.
>
Any help would be SO GREATLY appreciated!! I am very new at all this
so
if you have code or suggestions please tell me where it is supposed to
go as people often reference code and I have no idea where it goes.
>
Thanks so much everyone,
>
Brad G.
Why not omit the 1000+ portion? Just let the the counter use DMax + 1.
Then use the following expression as the Source:

=Format([displayedRunNumber], '00000')

Fred Zuckerman

Aug 1 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: samik_tanik | last post by:
I need to export a datagrid to Excel. I could did this. But, also need to keep the leading zeros in the data. How can I acheive this? Any help would be appreciated. -- Thanking you in...
2
by: Reggie | last post by:
It's kicking my butt. All I want to do is add 1 to each new records I add to my table using a form. The serial number is in the form 0001, 0002, 0003 etc, and increments for each record. If I...
3
by: jj | last post by:
example is I'm finding the max number within a certain criteria, and then adding one to that. However, most IDs are something like K00001 or R00223 So I want the next ID to be either K00002 or...
8
by: shumaker | last post by:
I see other posts where some say fields that will hold a number with leading zeros should be stored as text instead of numbers. This is very inefficient though, as a string of digit characters...
8
by: mantrid | last post by:
Hello I have the following code, where clicking yh1r is supposed to move h1 10px down and update the value of yh1 by 20 each time its clicked. what the code actually does is NOT move h1 and...
4
by: HandersonVA | last post by:
will it be possible to increase number as below automatically 00000001 00000002 00000003 .... whenever the row is inserted, number will be increased like above format. which data type should...
29
by: fdmfdmfdm | last post by:
let's say without checking including files, how do we to represent the biggest say int in a system? I ran across a book give this code: long int biggest = 0x7FFFFFFF; Does that mean the...
23
by: neha_chhatre | last post by:
which is the best format specifier(data type) if i have to work with decimal number. also please tell me the syntax for truncating a decimal number please reply as soon as possible
0
by: Monty | last post by:
Hi All, I am having a problem with leading zeros being stripped from fields in a CSV file when I bring them in using Jet/OleDB. In VB.Net/VS 2008, I am accessing a CSV file like so: sSQL =...
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
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
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...

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.