how to create a reservation number?

A

Arjan

Hi All,

I have a question.. I want to create a unique reservation number, for
invoice payments etc..
However, I want the reservation number to be build from two things;

first: the year we live in minus one 0 i.e. 2006 = 206, 2007 = 207, 2008 =
208 etc..
second: I want to add 3 digits to the 'year'number. These 3 digits will
start as 001 and every new reservation number will be added with 1.
so eventualy the reservationnumbers will look at this:
206001
206002
206003

Further more, when a new year starts a new serie has too begin..
207001
207002
207003

etc..

Is there anyone who can help me?

Thanks in advance..

Arjan
the Netherlands
 
K

Ken Snell \(MVP\)

Something like this, perhaps (assuming that the year 2010 would be 210):

Dim strYear As String, strReserNum As String
strYear = Year(Date())
strYear = Left(strYear, 1) & Right(strYear, 2)
strReserNum = strYear & CStr(CLng(Nz( _
DMax("ReservationNumberField", _
"TableName", "ReservationNumberField Like '" & _
strYear & "*'"), 0) + 1))

Note that your setup will fail after 999 reservation numbers, though.

However, I do not recommend that you store a single reservation number the
way you desire. Instead, I would use two fields in the table -- one to hold
the year (either as yyyy or in your shortened version) for the reservation,
and the other to hold the sequential number. Then you can use concatenation
(calculated field in a query or an expression as a textbox's Control Source,
etc.) to display the combined number. By separating the two "identity"
values, you'll make your queries for finding data within a given year or
years much easier to do because you won't need to extract the year as part
of the criterion (note what I had to do in the above code example to filter
to just the desired year).
 
A

Arjan

Hi Ken,

Thanks for your help!!

Ok, your right the set up will fail after 999 reservations, at this moment
it is not thinkable it is necesarry, but you never know!!
Therefore, let's forget about the 3 digits and just let number 1 be 1 and
add 1 so its possible to pass the 999..
so it will become 2061, 2062, ....2061001 etc..
However, when switching years the sequential number should start with 1
again. so there will be 2071, 2072 etc..

How can I do this?

fyi
the tablename is: 'boekingsformuliertabel'
and the fieldname is: 'reserveringsnummer'

I have no problem to combing two numbers to make one reservationnumber.. the
easiest way is preferable.

Thanks again!!

Arjan..
the Netherlands
 
K

Ken Snell \(MVP\)

You don't say if you're going to try my recommendation or not, so I will
just show you the same code as before but with the 1000 starting point:


Dim strYear As String, strReserNum As String
strYear = Year(Date())
strYear = Left(strYear, 1) & Right(strYear, 2)
strReserNum = strYear & CStr(CLng(Nz( _
DMax("ReservationNumberField", _
"TableName", "ReservationNumberField Like '" & _
strYear & "*'"), 1000) + 1))
 
K

Ken Snell \(MVP\)

Error in the code:

Dim strYear As String, strReserNum As String
strYear = Year(Date())
strYear = Left(strYear, 1) & Right(strYear, 2)
strReserNum = strYear & Format(CLng(Nz( _
DMax("ReservationNumberField", _
"TableName", "ReservationNumberField Like '" & _
strYear & "*'"), 0) + 1), "000")
 
A

Arjan

Hi Ken,

Thanks again,

However, I can't get it to work... :(
I have this field in my main table "boekingsformuliertabel" the field is
called "Reserveringsnummer" (does this have to be an autonumber? as it has
now the number propertie..)

The code you gave me, I have copied and pasted it in the form on the Got
Focus event.
The code I use is:
-----------------------------------------
Private Sub Reserveringsnummer_GotFocus()
'Hier wordt het reserveringsnummer bepaalt

Dim strYear As String, strReserNum As String
strYear = Year(Date)
strYear = Left(strYear, 1) & Right(strYear, 2)
strReserNum = strYear & Format(CLng(Nz( _
DMax("Reserveringsnummer", _
"boekingsformuliertabel", "Reserveringsnummer Like '" & _
strYear & "*'"), 0) + 1), "000")


End Sub
---------------------------------------------

While I run the code it simply doesn't give anything, It also does not give
an VBA error..

Do you have any idea??

note: I would like to use your recomendation. However, I'm not sure how to
set it up...

Thanks again..

Arjan
the Netherlands..
 
K

Ken Snell \(MVP\)

This code that I gave you assumes that the Reserveringsnummer is either a
long integer (number) field or a text field -- it'll work with either one.

The code that you posted puts the desired "new" number into the variable
strReserNum. You then need to write that value somewhere if you want to then
display and/or use it. If you want the new number to show in the
Reserveringsnummer textbox, you then would need one last code step:

Reserveringsnummer = strReserNum


However, I caution you about using the GotFocus event of the
Reserveringsnummer control to run this code. To receive the focus, the
Reserveringsnummer control needs to be enabled -- so unless you've also
locked the control, the user then is able to change the "new" number to
something else.
 
A

Arjan

Hi Ken,

thanks for you help... again.
what do you suggest? where should (can) I put the code? without the problem
where you are referring to?

Arjan
the Netherlands
 
K

Ken Snell \(MVP\)

Where you put the code depends upon when you want the number to be
generated.

If, for example, you want the number to be generated whenever a new record
is being created, you could use the form's Current event and test for a new
record:

Private Sub Form_Current()
If Me.NewRecord = True Then
' put that code here
End If
End Sub


If you want to generate the number whenever another value of some type has
been entered on the form, you could use the AfterUpdate event of the control
where that initial value is entered.

Or if you want to generate the number just before the form saves its data to
the table, you could use the form's BeforeUpdate event.
 
A

Arjan

Dear Ken,

I hope I on't start to bother you..thanks for the help again..

however, when I inputted the code it did it once, and from then one it
produces a '0' for every record.
this is the code I use:

Private Sub Algemeen_boekingsformulier_Current()
'Hier wordt het reserveringsnummer bepaalt
If Me.NewRecord = True Then
Dim strYear As String, strReserNum As String
strYear = Year(Date)
strYear = Left(strYear, 1) & Right(strYear, 2)
strReserNum = strYear & Format(CLng(Nz( _
DMax("Reserveringsnummer", _
"boekingsformuliertabel", "Reserveringsnummer Like '" & _
strYear & "*'"), 0) + 1), "000")
Reserveringsnummer = strReserNum

End If
End Sub

do you have any idea?

Once again, thanks for help and effort!!

Arjan
the Netherlands
 
K

Ken Snell \(MVP\)

Are you storing the generated reservation number into the table as part of
the data entry process on the form?
 
K

Ken Snell \(MVP\)

Are you running the VBA code in the form's Current event procedure? I don't
recognize the "name" (Algemeen_boekingsformulier_Current) of the Sub that
you posted.

I am perplexed by why the code would work the first time and then produce a
zero after that. The code cannot generate a zero based on my understanding
of your setup and based on the fact it's using the year as part of the
string. There must be something else about your setup that is still not
correct.

It appears you're using a non-US version of ACCESS, so I don't think I can
look at a copy of your database to see more details?
 
A

Arjan

Hi Ken,

I might have an idea what the cause of it is.. (I did not think of this
before..)
the "Algemeen_boekingsformulier_Current" is my main form.
However, I do not enter data on the main form, but on tabpages, which are
one the main form..

The database is almost 55 MB of size..
If this is too big, I can ectract the dataform for you..

Just let me know, and I will send it..

Arjan
The Netherlands
 
K

Ken Snell \(MVP\)

The correct name of the Sub must be this:

Private Sub Form_Current

Form must be in the name; you do not use the actual name of the form.

Change the sub's name, then you will need to "connect" the procedure to the
form's Current event property. Go to design view of the form, open the
Properties window, click on Event tab, go to textbox next to On Current
property, select [Event Procedure] from the dropdown box there, then click
on the three-dot button at far right of textbox. That will make the
connection.

A tab control is "invisible" with respect to referencing controls on it in
code. The controls on a tab page are "seen" by VBA just the same as if they
were on the form itself.
 
A

Arjan

Ken,

It works! However, it still has a little flaw in the code somehow...
the first number it generates is perfect.. 2061, but after the first number
it generates 2062062,
and then it generates 2062062063... etc..

The code I use is:
---------------------


Private Sub Form_Current()
'Hier wordt het reserveringsnummer bepaalt
If Me.NewRecord = True Then
Dim strYear As String, strReserNum As String
strYear = Year(Date)
strYear = Left(strYear, 1) & Right(strYear, 2)
strReserNum = strYear & Format(CLng(Nz( _
DMax("Reserveringsnummer", _
"boekingsformuliertabel", "Reserveringsnummer Like '" & "*'"), 0) + 1))
Reserveringsnummer = strReserNum
End If
End Sub

--------------------------

As you might see I altered the code a little bit because I followed your
advise and don't want to end at 206999....

Thanks for your help again..

Arjan





Ken Snell (MVP) said:
The correct name of the Sub must be this:

Private Sub Form_Current

Form must be in the name; you do not use the actual name of the form.

Change the sub's name, then you will need to "connect" the procedure to
the form's Current event property. Go to design view of the form, open the
Properties window, click on Event tab, go to textbox next to On Current
property, select [Event Procedure] from the dropdown box there, then click
on the three-dot button at far right of textbox. That will make the
connection.

A tab control is "invisible" with respect to referencing controls on it in
code. The controls on a tab page are "seen" by VBA just the same as if
they were on the form itself.

--

Ken Snell
<MS ACCESS MVP>


Arjan said:
Hi Ken,

I might have an idea what the cause of it is.. (I did not think of this
before..)
the "Algemeen_boekingsformulier_Current" is my main form.
However, I do not enter data on the main form, but on tabpages, which are
one the main form..

The database is almost 55 MB of size..
If this is too big, I can ectract the dataform for you..

Just let me know, and I will send it..

Arjan
The Netherlands
 
K

Ken Snell \(MVP\)

You broke the part of the DMax function that filtered the reservation
numbers. And I neglected to account for the fact that the reservation number
in the table contains the year portion as well.

So let's try this:

Private Sub Form_Current()
'Hier wordt het reserveringsnummer bepaalt
If Me.NewRecord = True Then
Dim strYear As String, strReserNum As String
Dim strNum As String
strYear = Year(Date)
strYear = Left(strYear, 1) & Right(strYear, 2)
strNum = Format(CLng(Nz( _
DMax("Reserveringsnummer", _
"boekingsformuliertabel", "Reserveringsnummer Like '" & _
strYear & "*'"), 0) + 1))
strNum = Mid(strNum, 4)
strReserNum = strYear & strNum
Reserveringsnummer = strReserNum
End If
End Sub


--

Ken Snell
<MS ACCESS MVP>


Arjan said:
Ken,

It works! However, it still has a little flaw in the code somehow...
the first number it generates is perfect.. 2061, but after the first
number
it generates 2062062,
and then it generates 2062062063... etc..

The code I use is:
---------------------


Private Sub Form_Current()
'Hier wordt het reserveringsnummer bepaalt
If Me.NewRecord = True Then
Dim strYear As String, strReserNum As String
strYear = Year(Date)
strYear = Left(strYear, 1) & Right(strYear, 2)
strReserNum = strYear & Format(CLng(Nz( _
DMax("Reserveringsnummer", _
"boekingsformuliertabel", "Reserveringsnummer Like '" & "*'"), 0) + 1))
Reserveringsnummer = strReserNum
End If
End Sub

--------------------------

As you might see I altered the code a little bit because I followed your
advise and don't want to end at 206999....

Thanks for your help again..

Arjan





Ken Snell (MVP) said:
The correct name of the Sub must be this:

Private Sub Form_Current

Form must be in the name; you do not use the actual name of the form.

Change the sub's name, then you will need to "connect" the procedure to
the form's Current event property. Go to design view of the form, open
the Properties window, click on Event tab, go to textbox next to On
Current property, select [Event Procedure] from the dropdown box there,
then click on the three-dot button at far right of textbox. That will
make the connection.

A tab control is "invisible" with respect to referencing controls on it
in code. The controls on a tab page are "seen" by VBA just the same as if
they were on the form itself.

--

Ken Snell
<MS ACCESS MVP>


Arjan said:
Hi Ken,

I might have an idea what the cause of it is.. (I did not think of this
before..)
the "Algemeen_boekingsformulier_Current" is my main form.
However, I do not enter data on the main form, but on tabpages, which
are
one the main form..

The database is almost 55 MB of size..
If this is too big, I can ectract the dataform for you..

Just let me know, and I will send it..

Arjan
The Netherlands

"Ken Snell (MVP)" <[email protected]> schreef in bericht
Are you running the VBA code in the form's Current event procedure? I
don't recognize the "name" (Algemeen_boekingsformulier_Current) of the
Sub that you posted.

I am perplexed by why the code would work the first time and then
produce a zero after that. The code cannot generate a zero based on my
understanding of your setup and based on the fact it's using the year
as part of the string. There must be something else about your setup
that is still not correct.

It appears you're using a non-US version of ACCESS, so I don't think I
can look at a copy of your database to see more details?

--

Ken Snell
<MS ACCESS MVP>


Yes, I do

Almost every data is stored in one (small) table..


"Ken Snell (MVP)" <[email protected]> schreef in
bericht Are you storing the generated reservation number into the table as
part of the data entry process on the form?

--

Ken Snell
<MS ACCESS MVP>

Dear Ken,

I hope I on't start to bother you..thanks for the help again..

however, when I inputted the code it did it once, and from then one
it produces a '0' for every record.
this is the code I use:

Private Sub Algemeen_boekingsformulier_Current()
'Hier wordt het reserveringsnummer bepaalt
If Me.NewRecord = True Then
Dim strYear As String, strReserNum As String
strYear = Year(Date)
strYear = Left(strYear, 1) & Right(strYear, 2)
strReserNum = strYear & Format(CLng(Nz( _
DMax("Reserveringsnummer", _
"boekingsformuliertabel", "Reserveringsnummer Like '" & _
strYear & "*'"), 0) + 1), "000")
Reserveringsnummer = strReserNum

End If
End Sub

do you have any idea?

Once again, thanks for help and effort!!

Arjan
the Netherlands




"Ken Snell (MVP)" <[email protected]> schreef in
bericht Where you put the code depends upon when you want the number to be
generated.

If, for example, you want the number to be generated whenever a new
record is being created, you could use the form's Current event and
test for a new record:

Private Sub Form_Current()
If Me.NewRecord = True Then
' put that code here
End If
End Sub


If you want to generate the number whenever another value of some
type has been entered on the form, you could use the AfterUpdate
event of the control where that initial value is entered.

Or if you want to generate the number just before the form saves
its data to the table, you could use the form's BeforeUpdate event.

--

Ken Snell
<MS ACCESS MVP>


Hi Ken,

thanks for you help... again.
what do you suggest? where should (can) I put the code? without
the problem where you are referring to?

Arjan
the Netherlands



"Ken Snell (MVP)" <[email protected]> schreef in
bericht This code that I gave you assumes that the Reserveringsnummer is
either a long integer (number) field or a text field -- it'll
work with either one.

The code that you posted puts the desired "new" number into the
variable strReserNum. You then need to write that value somewhere
if you want to then display and/or use it. If you want the new
number to show in the Reserveringsnummer textbox, you then would
need one last code step:

Reserveringsnummer = strReserNum


However, I caution you about using the GotFocus event of the
Reserveringsnummer control to run this code. To receive the
focus, the Reserveringsnummer control needs to be enabled -- so
unless you've also locked the control, the user then is able to
change the "new" number to something else.
--

Ken Snell
<MS ACCESS MVP>



Hi Ken,

Thanks again,

However, I can't get it to work... :(
I have this field in my main table "boekingsformuliertabel" the
field is called "Reserveringsnummer" (does this have to be an
autonumber? as it has now the number propertie..)

The code you gave me, I have copied and pasted it in the form on
the Got Focus event.
The code I use is:
-----------------------------------------
Private Sub Reserveringsnummer_GotFocus()
'Hier wordt het reserveringsnummer bepaalt

Dim strYear As String, strReserNum As String
strYear = Year(Date)
strYear = Left(strYear, 1) & Right(strYear, 2)
strReserNum = strYear & Format(CLng(Nz( _
DMax("Reserveringsnummer", _
"boekingsformuliertabel", "Reserveringsnummer Like '" & _
strYear & "*'"), 0) + 1), "000")


End Sub
---------------------------------------------

While I run the code it simply doesn't give anything, It also
does not give an VBA error..

Do you have any idea??

note: I would like to use your recomendation. However, I'm not
sure how to set it up...

Thanks again..

Arjan
the Netherlands..












"Ken Snell (MVP)" <[email protected]> schreef in
bericht Error in the code:

Dim strYear As String, strReserNum As String
strYear = Year(Date())
strYear = Left(strYear, 1) & Right(strYear, 2)
strReserNum = strYear & Format(CLng(Nz( _
DMax("ReservationNumberField", _
"TableName", "ReservationNumberField Like '" & _
strYear & "*'"), 0) + 1), "000")


--

Ken Snell
<MS ACCESS MVP>

message Something like this, perhaps (assuming that the year 2010
would be 210):

Dim strYear As String, strReserNum As String
strYear = Year(Date())
strYear = Left(strYear, 1) & Right(strYear, 2)
strReserNum = strYear & CStr(CLng(Nz( _
DMax("ReservationNumberField", _
"TableName", "ReservationNumberField Like '" & _
strYear & "*'"), 0) + 1))

Note that your setup will fail after 999 reservation numbers,
though.

However, I do not recommend that you store a single
reservation number the way you desire. Instead, I would use
two fields in the table -- one to hold the year (either as
yyyy or in your shortened version) for the reservation, and
the other to hold the sequential number. Then you can use
concatenation (calculated field in a query or an expression as
a textbox's Control Source, etc.) to display the combined
number. By separating the two "identity" values, you'll make
your queries for finding data within a given year or years
much easier to do because you won't need to extract the year
as part of the criterion (note what I had to do in the above
code example to filter to just the desired year).

--

Ken Snell
<MS ACCESS MVP>


Hi All,

I have a question.. I want to create a unique reservation
number, for
invoice payments etc..
However, I want the reservation number to be build from two
things;

first: the year we live in minus one 0 i.e. 2006 = 206, 2007
= 207, 2008 =
208 etc..
second: I want to add 3 digits to the 'year'number. These 3
digits will
start as 001 and every new reservation number will be added
with 1.
so eventualy the reservationnumbers will look at this:
206001
206002
206003

Further more, when a new year starts a new serie has too
begin..
207001
207002
207003

etc..

Is there anyone who can help me?

Thanks in advance..

Arjan
the Netherlands
 
A

Arjan

Dear Ken,

Sorry that you did not receive any reply..
I had a couple of days off.... that's why..

However, It works exactly how I want it to!! thanks for your help and
effort!!

Arjan..


Ken Snell (MVP) said:
You broke the part of the DMax function that filtered the reservation
numbers. And I neglected to account for the fact that the reservation
number in the table contains the year portion as well.

So let's try this:

Private Sub Form_Current()
'Hier wordt het reserveringsnummer bepaalt
If Me.NewRecord = True Then
Dim strYear As String, strReserNum As String
Dim strNum As String
strYear = Year(Date)
strYear = Left(strYear, 1) & Right(strYear, 2)
strNum = Format(CLng(Nz( _
DMax("Reserveringsnummer", _
"boekingsformuliertabel", "Reserveringsnummer Like '" & _
strYear & "*'"), 0) + 1))
strNum = Mid(strNum, 4)
strReserNum = strYear & strNum
Reserveringsnummer = strReserNum
End If
End Sub


--

Ken Snell
<MS ACCESS MVP>


Arjan said:
Ken,

It works! However, it still has a little flaw in the code somehow...
the first number it generates is perfect.. 2061, but after the first
number
it generates 2062062,
and then it generates 2062062063... etc..

The code I use is:
---------------------


Private Sub Form_Current()
'Hier wordt het reserveringsnummer bepaalt
If Me.NewRecord = True Then
Dim strYear As String, strReserNum As String
strYear = Year(Date)
strYear = Left(strYear, 1) & Right(strYear, 2)
strReserNum = strYear & Format(CLng(Nz( _
DMax("Reserveringsnummer", _
"boekingsformuliertabel", "Reserveringsnummer Like '" & "*'"), 0) +
1))
Reserveringsnummer = strReserNum
End If
End Sub

--------------------------

As you might see I altered the code a little bit because I followed your
advise and don't want to end at 206999....

Thanks for your help again..

Arjan





Ken Snell (MVP) said:
The correct name of the Sub must be this:

Private Sub Form_Current

Form must be in the name; you do not use the actual name of the form.

Change the sub's name, then you will need to "connect" the procedure to
the form's Current event property. Go to design view of the form, open
the Properties window, click on Event tab, go to textbox next to On
Current property, select [Event Procedure] from the dropdown box there,
then click on the three-dot button at far right of textbox. That will
make the connection.

A tab control is "invisible" with respect to referencing controls on it
in code. The controls on a tab page are "seen" by VBA just the same as
if they were on the form itself.

--

Ken Snell
<MS ACCESS MVP>


Hi Ken,

I might have an idea what the cause of it is.. (I did not think of this
before..)
the "Algemeen_boekingsformulier_Current" is my main form.
However, I do not enter data on the main form, but on tabpages, which
are
one the main form..

The database is almost 55 MB of size..
If this is too big, I can ectract the dataform for you..

Just let me know, and I will send it..

Arjan
The Netherlands

"Ken Snell (MVP)" <[email protected]> schreef in bericht
Are you running the VBA code in the form's Current event procedure? I
don't recognize the "name" (Algemeen_boekingsformulier_Current) of
the Sub that you posted.

I am perplexed by why the code would work the first time and then
produce a zero after that. The code cannot generate a zero based on my
understanding of your setup and based on the fact it's using the year
as part of the string. There must be something else about your setup
that is still not correct.

It appears you're using a non-US version of ACCESS, so I don't think I
can look at a copy of your database to see more details?

--

Ken Snell
<MS ACCESS MVP>


Yes, I do

Almost every data is stored in one (small) table..


"Ken Snell (MVP)" <[email protected]> schreef in
bericht Are you storing the generated reservation number into the table as
part of the data entry process on the form?

--

Ken Snell
<MS ACCESS MVP>

Dear Ken,

I hope I on't start to bother you..thanks for the help again..

however, when I inputted the code it did it once, and from then one
it produces a '0' for every record.
this is the code I use:

Private Sub Algemeen_boekingsformulier_Current()
'Hier wordt het reserveringsnummer bepaalt
If Me.NewRecord = True Then
Dim strYear As String, strReserNum As String
strYear = Year(Date)
strYear = Left(strYear, 1) & Right(strYear, 2)
strReserNum = strYear & Format(CLng(Nz( _
DMax("Reserveringsnummer", _
"boekingsformuliertabel", "Reserveringsnummer Like '" & _
strYear & "*'"), 0) + 1), "000")
Reserveringsnummer = strReserNum

End If
End Sub

do you have any idea?

Once again, thanks for help and effort!!

Arjan
the Netherlands




"Ken Snell (MVP)" <[email protected]> schreef in
bericht Where you put the code depends upon when you want the number to be
generated.

If, for example, you want the number to be generated whenever a
new record is being created, you could use the form's Current
event and test for a new record:

Private Sub Form_Current()
If Me.NewRecord = True Then
' put that code here
End If
End Sub


If you want to generate the number whenever another value of some
type has been entered on the form, you could use the AfterUpdate
event of the control where that initial value is entered.

Or if you want to generate the number just before the form saves
its data to the table, you could use the form's BeforeUpdate
event.

--

Ken Snell
<MS ACCESS MVP>


Hi Ken,

thanks for you help... again.
what do you suggest? where should (can) I put the code? without
the problem where you are referring to?

Arjan
the Netherlands



"Ken Snell (MVP)" <[email protected]> schreef in
bericht This code that I gave you assumes that the Reserveringsnummer is
either a long integer (number) field or a text field -- it'll
work with either one.

The code that you posted puts the desired "new" number into the
variable strReserNum. You then need to write that value
somewhere if you want to then display and/or use it. If you want
the new number to show in the Reserveringsnummer textbox, you
then would need one last code step:

Reserveringsnummer = strReserNum


However, I caution you about using the GotFocus event of the
Reserveringsnummer control to run this code. To receive the
focus, the Reserveringsnummer control needs to be enabled -- so
unless you've also locked the control, the user then is able to
change the "new" number to something else.
--

Ken Snell
<MS ACCESS MVP>



Hi Ken,

Thanks again,

However, I can't get it to work... :(
I have this field in my main table "boekingsformuliertabel" the
field is called "Reserveringsnummer" (does this have to be an
autonumber? as it has now the number propertie..)

The code you gave me, I have copied and pasted it in the form
on the Got Focus event.
The code I use is:
-----------------------------------------
Private Sub Reserveringsnummer_GotFocus()
'Hier wordt het reserveringsnummer bepaalt

Dim strYear As String, strReserNum As String
strYear = Year(Date)
strYear = Left(strYear, 1) & Right(strYear, 2)
strReserNum = strYear & Format(CLng(Nz( _
DMax("Reserveringsnummer", _
"boekingsformuliertabel", "Reserveringsnummer Like '" & _
strYear & "*'"), 0) + 1), "000")


End Sub
---------------------------------------------

While I run the code it simply doesn't give anything, It also
does not give an VBA error..

Do you have any idea??

note: I would like to use your recomendation. However, I'm not
sure how to set it up...

Thanks again..

Arjan
the Netherlands..












"Ken Snell (MVP)" <[email protected]> schreef in
bericht Error in the code:

Dim strYear As String, strReserNum As String
strYear = Year(Date())
strYear = Left(strYear, 1) & Right(strYear, 2)
strReserNum = strYear & Format(CLng(Nz( _
DMax("ReservationNumberField", _
"TableName", "ReservationNumberField Like '" & _
strYear & "*'"), 0) + 1), "000")


--

Ken Snell
<MS ACCESS MVP>

message Something like this, perhaps (assuming that the year 2010
would be 210):

Dim strYear As String, strReserNum As String
strYear = Year(Date())
strYear = Left(strYear, 1) & Right(strYear, 2)
strReserNum = strYear & CStr(CLng(Nz( _
DMax("ReservationNumberField", _
"TableName", "ReservationNumberField Like '" & _
strYear & "*'"), 0) + 1))

Note that your setup will fail after 999 reservation numbers,
though.

However, I do not recommend that you store a single
reservation number the way you desire. Instead, I would use
two fields in the table -- one to hold the year (either as
yyyy or in your shortened version) for the reservation, and
the other to hold the sequential number. Then you can use
concatenation (calculated field in a query or an expression
as a textbox's Control Source, etc.) to display the combined
number. By separating the two "identity" values, you'll make
your queries for finding data within a given year or years
much easier to do because you won't need to extract the year
as part of the criterion (note what I had to do in the above
code example to filter to just the desired year).

--

Ken Snell
<MS ACCESS MVP>


Hi All,

I have a question.. I want to create a unique reservation
number, for
invoice payments etc..
However, I want the reservation number to be build from two
things;

first: the year we live in minus one 0 i.e. 2006 = 206, 2007
= 207, 2008 =
208 etc..
second: I want to add 3 digits to the 'year'number. These 3
digits will
start as 001 and every new reservation number will be added
with 1.
so eventualy the reservationnumbers will look at this:
206001
206002
206003

Further more, when a new year starts a new serie has too
begin..
207001
207002
207003

etc..

Is there anyone who can help me?

Thanks in advance..

Arjan
the Netherlands
 
K

Ken Snell \(MVP\)

You're welcome. Glad we found the solution!

--

Ken Snell
<MS ACCESS MVP>

Arjan said:
Dear Ken,

Sorry that you did not receive any reply..
I had a couple of days off.... that's why..

However, It works exactly how I want it to!! thanks for your help and
effort!!

Arjan..


< snipped >
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top