473,804 Members | 3,515 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 "displayedRunNu mber" 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_BeforeUpda te(Cancel As Integer)

If Me.NewRecord Then
Me!displayedRun Number = Nz(DMax("displa yedRunNumber", "fields"),
1000) + 1

End If

End Sub

This basically starts displayedRunNum ber 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 displayedRunNum ber 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 3308
<br***********@ gmail.comwrote in message
news:11******** **************@ m79g2000cwm.goo glegroups.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 "displayedRunNu mber" 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_BeforeUpda te(Cancel As Integer)

If Me.NewRecord Then
Me!displayedRun Number = Nz(DMax("displa yedRunNumber", "fields"),
1000) + 1

End If

End Sub

This basically starts displayedRunNum ber 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 displayedRunNum ber 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([displayedRunNum ber], '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_BeforeUpda te(Cancel As Integer)

If Me.NewRecord Then
Me!displayedRun Number = (DMax("displaye dRunNumber", "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([displayedRunNum ber],'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.goo glegroups.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 "displayedRunNu mber" 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_BeforeUpda te(Cancel As Integer)

If Me.NewRecord Then
Me!displayedRun Number = Nz(DMax("displa yedRunNumber", "fields"),
1000) + 1

End If

End Sub

This basically starts displayedRunNum ber 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 displayedRunNum ber 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([displayedRunNum ber], '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 [displayedRunNum ber] ? 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******** *************@b 28g2000cwb.goog legroups.com...
Fred,

Thanks for the help...

I changed the before update field of the form to:

Private Sub Form_BeforeUpda te(Cancel As Integer)

If Me.NewRecord Then
Me!displayedRun Number = (DMax("displaye dRunNumber", "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([displayedRunNum ber],'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.goo glegroups.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 "displayedRunNu mber" 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_BeforeUpda te(Cancel As Integer)
>
If Me.NewRecord Then
Me!displayedRun Number = Nz(DMax("displa yedRunNumber", "fields"),
1000) + 1
>
End If
>
End Sub
>
This basically starts displayedRunNum ber 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 displayedRunNum ber 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([displayedRunNum ber], '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
11515
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 anticipation, Regards,
2
2435
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 enter the value in the table directly it retains the leading zero's however if I use the dmax function and add one to it it's store as 1, 2, 3 etc. I'm stumped. Can I do this as a default value in the table? Any advice is appreciated. Thanks in...
3
2027
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 R00224 Unfortunately Access is stripping out the leading 0s leaving me with an ID of K3 or R224. With PHP I'm able to do something like:
8
2477
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 takes up much more memory than a 32bit or even a 64bit int. Storing as a number still allows for formatting when displaying the number, correct? I am creating a table and would like opinions regarding this please.
8
2390
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 instead of incrementing yh1 from 0 to 20 to 40 etc it doubles it and appends it to the original value each time eg 0 to 20 to 4020 to 804020 to 160804020 <div id='h1' style='position:absolute; top:<?php echo $yh1/2;?>px; <?php $h1; ?></div>
4
11782
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 I select and do some other setting to record like that?
29
2481
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 long int at that system is only 32 bits? If we know in a particular system, the long int is 64 bits, shall we write:
23
9807
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
4108
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 = "SELECT * FROM " sConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _ Microsoft.VisualBasic.FileIO.FileSystem.GetParentPath(msFile) & _
0
9576
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10568
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10311
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9138
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5516
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4292
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3813
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2988
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.