Formula?

T

Tom

I need a way for one of my fields to change
incrementally as new records are created.
This field will always have 9 numbers max.
It must start with todays date in the
format 051117 and then 001
This should change to 002 for the next record
The date should also change;
i.e. at 11:59pm the last record is
051117052 at 12:00am it will automatically
change to 051118001
there will never be a "000" record.

Any thoughts would be greatly appreciated.

Tom
 
K

Klatuu

I think this question has set a record for the number of times asked. Were I
smarter, I would save the answer in a text file so I could cut and paste and
not have to write it again (3rd time this week):

Here is a function that will give you the next number.

Function GetNextNumber as String
Dim strCurrDate as String
Dim varHighValue as Variant

strCurrDate = Format(Date, "yymmdd")
varHighValue = DMax("[MyField]", "MyTable", "Left([MyField], 6) = '" _
& strCurrDate & "'")
If IsNull(varHighValue) Then
GetNextNumber = strCurrDate & "001"
Else
GetNextNumber = =Format(CLng(Left(varHighValue,6))+1,"000000000")
End If
End Function

To use it, make it the Default Value of the text box where you display the
number
 
T

Tom

I got the follow message trying to save the table,
in "design view" "The expression you entered contains invalid syntax. You
may have entered an operand without an operator."
I cut and pasted the formula
Tom

Klatuu said:
I think this question has set a record for the number of times asked. Were I
smarter, I would save the answer in a text file so I could cut and paste and
not have to write it again (3rd time this week):

Here is a function that will give you the next number.

Function GetNextNumber as String
Dim strCurrDate as String
Dim varHighValue as Variant

strCurrDate = Format(Date, "yymmdd")
varHighValue = DMax("[MyField]", "MyTable", "Left([MyField], 6) = '" _
& strCurrDate & "'")
If IsNull(varHighValue) Then
GetNextNumber = strCurrDate & "001"
Else
GetNextNumber = =Format(CLng(Left(varHighValue,6))+1,"000000000")
End If
End Function

To use it, make it the Default Value of the text box where you display the
number
Tom said:
I need a way for one of my fields to change
incrementally as new records are created.
This field will always have 9 numbers max.
It must start with todays date in the
format 051117 and then 001
This should change to 002 for the next record
The date should also change;
i.e. at 11:59pm the last record is
051117052 at 12:00am it will automatically
change to 051118001
there will never be a "000" record.

Any thoughts would be greatly appreciated.

Tom
 
R

rico

You need to open a new Module (in main database window), paste the code into
there. save the module (basGetNextNumber would be a good name)

THEN go to your table and type GetNextNumber() into the default vlaue of
your field.

HTH

Rico

Tom said:
I got the follow message trying to save the table,
in "design view" "The expression you entered contains invalid syntax. You
may have entered an operand without an operator."
I cut and pasted the formula
Tom

Klatuu said:
I think this question has set a record for the number of times asked. Were I
smarter, I would save the answer in a text file so I could cut and paste and
not have to write it again (3rd time this week):

Here is a function that will give you the next number.

Function GetNextNumber as String
Dim strCurrDate as String
Dim varHighValue as Variant

strCurrDate = Format(Date, "yymmdd")
varHighValue = DMax("[MyField]", "MyTable", "Left([MyField], 6) = '" _
& strCurrDate & "'")
If IsNull(varHighValue) Then
GetNextNumber = strCurrDate & "001"
Else
GetNextNumber = =Format(CLng(Left(varHighValue,6))+1,"000000000")
End If
End Function

To use it, make it the Default Value of the text box where you display the
number
Tom said:
I need a way for one of my fields to change
incrementally as new records are created.
This field will always have 9 numbers max.
It must start with todays date in the
format 051117 and then 001
This should change to 002 for the next record
The date should also change;
i.e. at 11:59pm the last record is
051117052 at 12:00am it will automatically
change to 051118001
there will never be a "000" record.

Any thoughts would be greatly appreciated.

Tom
 
T

Tom

Rico,
It gave me a syntax error
and highlighted

GetNextNumber = =Format(CLng(Left(varHighValue,6))+1,"000000000")

Then I clicked "OK" and highlighted in Yellow was:

Function GetNextNumber as String

I also noticed that when I went to save it, next to "General"
it changed from "Declarations" to "GetNextNumber"

Tom

rico said:
You need to open a new Module (in main database window), paste the code into
there. save the module (basGetNextNumber would be a good name)

THEN go to your table and type GetNextNumber() into the default vlaue of
your field.

HTH

Rico

Tom said:
I got the follow message trying to save the table,
in "design view" "The expression you entered contains invalid syntax. You
may have entered an operand without an operator."
I cut and pasted the formula
Tom

Klatuu said:
I think this question has set a record for the number of times asked. Were I
smarter, I would save the answer in a text file so I could cut and paste and
not have to write it again (3rd time this week):

Here is a function that will give you the next number.

Function GetNextNumber as String
Dim strCurrDate as String
Dim varHighValue as Variant

strCurrDate = Format(Date, "yymmdd")
varHighValue = DMax("[MyField]", "MyTable", "Left([MyField], 6) = '" _
& strCurrDate & "'")
If IsNull(varHighValue) Then
GetNextNumber = strCurrDate & "001"
Else
GetNextNumber = =Format(CLng(Left(varHighValue,6))+1,"000000000")
End If
End Function

To use it, make it the Default Value of the text box where you display the
number
:

I need a way for one of my fields to change
incrementally as new records are created.
This field will always have 9 numbers max.
It must start with todays date in the
format 051117 and then 001
This should change to 002 for the next record
The date should also change;
i.e. at 11:59pm the last record is
051117052 at 12:00am it will automatically
change to 051118001
there will never be a "000" record.

Any thoughts would be greatly appreciated.

Tom
 
K

Klatuu

typo on my part, sorry. Should be:

GetNextNumber = Format(CLng(Left(varHighValue,6))+1,"000000000")

It doesn't need to be in a standard module unless you plan to use it else
where. If it is for this form only, put it in the General section of your
form module.

Tom said:
Rico,
It gave me a syntax error
and highlighted

GetNextNumber = =Format(CLng(Left(varHighValue,6))+1,"000000000")

Then I clicked "OK" and highlighted in Yellow was:

Function GetNextNumber as String

I also noticed that when I went to save it, next to "General"
it changed from "Declarations" to "GetNextNumber"

Tom

rico said:
You need to open a new Module (in main database window), paste the code into
there. save the module (basGetNextNumber would be a good name)

THEN go to your table and type GetNextNumber() into the default vlaue of
your field.

HTH

Rico

Tom said:
I got the follow message trying to save the table,
in "design view" "The expression you entered contains invalid syntax. You
may have entered an operand without an operator."
I cut and pasted the formula
Tom

:

I think this question has set a record for the number of times asked. Were I
smarter, I would save the answer in a text file so I could cut and paste and
not have to write it again (3rd time this week):

Here is a function that will give you the next number.

Function GetNextNumber as String
Dim strCurrDate as String
Dim varHighValue as Variant

strCurrDate = Format(Date, "yymmdd")
varHighValue = DMax("[MyField]", "MyTable", "Left([MyField], 6) = '" _
& strCurrDate & "'")
If IsNull(varHighValue) Then
GetNextNumber = strCurrDate & "001"
Else
GetNextNumber = =Format(CLng(Left(varHighValue,6))+1,"000000000")
End If
End Function

To use it, make it the Default Value of the text box where you display the
number
:

I need a way for one of my fields to change
incrementally as new records are created.
This field will always have 9 numbers max.
It must start with todays date in the
format 051117 and then 001
This should change to 002 for the next record
The date should also change;
i.e. at 11:59pm the last record is
051117052 at 12:00am it will automatically
change to 051118001
there will never be a "000" record.

Any thoughts would be greatly appreciated.

Tom
 
T

Tom

Klatuu,
Now it comes up with
#Name?
In the field of "Form View"

No syntax or other errors
Tom

Klatuu said:
typo on my part, sorry. Should be:

GetNextNumber = Format(CLng(Left(varHighValue,6))+1,"000000000")

It doesn't need to be in a standard module unless you plan to use it else
where. If it is for this form only, put it in the General section of your
form module.

Tom said:
Rico,
It gave me a syntax error
and highlighted

GetNextNumber = =Format(CLng(Left(varHighValue,6))+1,"000000000")

Then I clicked "OK" and highlighted in Yellow was:

Function GetNextNumber as String

I also noticed that when I went to save it, next to "General"
it changed from "Declarations" to "GetNextNumber"

Tom

rico said:
You need to open a new Module (in main database window), paste the code into
there. save the module (basGetNextNumber would be a good name)

THEN go to your table and type GetNextNumber() into the default vlaue of
your field.

HTH

Rico

:

I got the follow message trying to save the table,
in "design view" "The expression you entered contains invalid syntax. You
may have entered an operand without an operator."
I cut and pasted the formula
Tom

:

I think this question has set a record for the number of times asked. Were I
smarter, I would save the answer in a text file so I could cut and paste and
not have to write it again (3rd time this week):

Here is a function that will give you the next number.

Function GetNextNumber as String
Dim strCurrDate as String
Dim varHighValue as Variant

strCurrDate = Format(Date, "yymmdd")
varHighValue = DMax("[MyField]", "MyTable", "Left([MyField], 6) = '" _
& strCurrDate & "'")
If IsNull(varHighValue) Then
GetNextNumber = strCurrDate & "001"
Else
GetNextNumber = =Format(CLng(Left(varHighValue,6))+1,"000000000")
End If
End Function

To use it, make it the Default Value of the text box where you display the
number
:

I need a way for one of my fields to change
incrementally as new records are created.
This field will always have 9 numbers max.
It must start with todays date in the
format 051117 and then 001
This should change to 002 for the next record
The date should also change;
i.e. at 11:59pm the last record is
051117052 at 12:00am it will automatically
change to 051118001
there will never be a "000" record.

Any thoughts would be greatly appreciated.

Tom
 
K

Klatuu

I believe that means it can't find the function GetNextNumber. Either you
spelled it incorrectly in the function or where you call it, or the function
is not where the form can see it.
Check your spelling, and if that is not it, tell me where you put the
function?

Tom said:
Klatuu,
Now it comes up with
#Name?
In the field of "Form View"

No syntax or other errors
Tom

Klatuu said:
typo on my part, sorry. Should be:

GetNextNumber = Format(CLng(Left(varHighValue,6))+1,"000000000")

It doesn't need to be in a standard module unless you plan to use it else
where. If it is for this form only, put it in the General section of your
form module.

Tom said:
Rico,
It gave me a syntax error
and highlighted

GetNextNumber = =Format(CLng(Left(varHighValue,6))+1,"000000000")

Then I clicked "OK" and highlighted in Yellow was:

Function GetNextNumber as String

I also noticed that when I went to save it, next to "General"
it changed from "Declarations" to "GetNextNumber"

Tom

:

You need to open a new Module (in main database window), paste the code into
there. save the module (basGetNextNumber would be a good name)

THEN go to your table and type GetNextNumber() into the default vlaue of
your field.

HTH

Rico

:

I got the follow message trying to save the table,
in "design view" "The expression you entered contains invalid syntax. You
may have entered an operand without an operator."
I cut and pasted the formula
Tom

:

I think this question has set a record for the number of times asked. Were I
smarter, I would save the answer in a text file so I could cut and paste and
not have to write it again (3rd time this week):

Here is a function that will give you the next number.

Function GetNextNumber as String
Dim strCurrDate as String
Dim varHighValue as Variant

strCurrDate = Format(Date, "yymmdd")
varHighValue = DMax("[MyField]", "MyTable", "Left([MyField], 6) = '" _
& strCurrDate & "'")
If IsNull(varHighValue) Then
GetNextNumber = strCurrDate & "001"
Else
GetNextNumber = =Format(CLng(Left(varHighValue,6))+1,"000000000")
End If
End Function

To use it, make it the Default Value of the text box where you display the
number
:

I need a way for one of my fields to change
incrementally as new records are created.
This field will always have 9 numbers max.
It must start with todays date in the
format 051117 and then 001
This should change to 002 for the next record
The date should also change;
i.e. at 11:59pm the last record is
051117052 at 12:00am it will automatically
change to 051118001
there will never be a "000" record.

Any thoughts would be greatly appreciated.

Tom
 
T

Tom

Forgive me, I'm stupid. I've never touch this before.
I need my hand held. I have the formula ready to
paste. I just need to know exactly "step, by step"
what to click on where to go.
I had to reset my puter to yesterday to get rid
of my stupidity.
Do you want me in "forms" or "tables"
Do you want me to select "tools" then "macros"
I don't know.
Tom

Klatuu said:
I believe that means it can't find the function GetNextNumber. Either you
spelled it incorrectly in the function or where you call it, or the function
is not where the form can see it.
Check your spelling, and if that is not it, tell me where you put the
function?

Tom said:
Klatuu,
Now it comes up with
#Name?
In the field of "Form View"

No syntax or other errors
Tom

Klatuu said:
typo on my part, sorry. Should be:

GetNextNumber = Format(CLng(Left(varHighValue,6))+1,"000000000")

It doesn't need to be in a standard module unless you plan to use it else
where. If it is for this form only, put it in the General section of your
form module.

:

Rico,
It gave me a syntax error
and highlighted

GetNextNumber = =Format(CLng(Left(varHighValue,6))+1,"000000000")

Then I clicked "OK" and highlighted in Yellow was:

Function GetNextNumber as String

I also noticed that when I went to save it, next to "General"
it changed from "Declarations" to "GetNextNumber"

Tom

:

You need to open a new Module (in main database window), paste the code into
there. save the module (basGetNextNumber would be a good name)

THEN go to your table and type GetNextNumber() into the default vlaue of
your field.

HTH

Rico

:

I got the follow message trying to save the table,
in "design view" "The expression you entered contains invalid syntax. You
may have entered an operand without an operator."
I cut and pasted the formula
Tom

:

I think this question has set a record for the number of times asked. Were I
smarter, I would save the answer in a text file so I could cut and paste and
not have to write it again (3rd time this week):

Here is a function that will give you the next number.

Function GetNextNumber as String
Dim strCurrDate as String
Dim varHighValue as Variant

strCurrDate = Format(Date, "yymmdd")
varHighValue = DMax("[MyField]", "MyTable", "Left([MyField], 6) = '" _
& strCurrDate & "'")
If IsNull(varHighValue) Then
GetNextNumber = strCurrDate & "001"
Else
GetNextNumber = =Format(CLng(Left(varHighValue,6))+1,"000000000")
End If
End Function

To use it, make it the Default Value of the text box where you display the
number
:

I need a way for one of my fields to change
incrementally as new records are created.
This field will always have 9 numbers max.
It must start with todays date in the
format 051117 and then 001
This should change to 002 for the next record
The date should also change;
i.e. at 11:59pm the last record is
051117052 at 12:00am it will automatically
change to 051118001
there will never be a "000" record.

Any thoughts would be greatly appreciated.

Tom
 
K

Klatuu

Okay.
Open the form in Design view where you have the control you want the number
to be in
Click the Code icon on the Toolbar. (it looks like a box with little blue,
red, and yellow balls on it.
The VB Editor will open.
The Caption at the top of the screen should have the name of your form in it.
Go to the top of the form module.
The two panes at the top should say (General) on the left and (Declarations)
on the right. Just below that there should be some option statments Like:
Option Compare Database
Option Explicit
etc.

Doesn't matter what they say, just trying to get you oriented.
Copy the code I sent and paste it just below the last Option statement, but
before any other code you see.

You will need to replace my made up names with the correct names for your
own objects.

Save it.
Close the VB Editor
On your form, right click on the text box where you want the number to
display.
Select Properties from the dropdown menu.
Look for the property named Default Value
Put this in the box next to it:
=GetNextNumber()
Save it.
Test it,
let me know what happens.




Tom said:
Forgive me, I'm stupid. I've never touch this before.
I need my hand held. I have the formula ready to
paste. I just need to know exactly "step, by step"
what to click on where to go.
I had to reset my puter to yesterday to get rid
of my stupidity.
Do you want me in "forms" or "tables"
Do you want me to select "tools" then "macros"
I don't know.
Tom

Klatuu said:
I believe that means it can't find the function GetNextNumber. Either you
spelled it incorrectly in the function or where you call it, or the function
is not where the form can see it.
Check your spelling, and if that is not it, tell me where you put the
function?

Tom said:
Klatuu,
Now it comes up with
#Name?
In the field of "Form View"

No syntax or other errors
Tom

:

typo on my part, sorry. Should be:

GetNextNumber = Format(CLng(Left(varHighValue,6))+1,"000000000")

It doesn't need to be in a standard module unless you plan to use it else
where. If it is for this form only, put it in the General section of your
form module.

:

Rico,
It gave me a syntax error
and highlighted

GetNextNumber = =Format(CLng(Left(varHighValue,6))+1,"000000000")

Then I clicked "OK" and highlighted in Yellow was:

Function GetNextNumber as String

I also noticed that when I went to save it, next to "General"
it changed from "Declarations" to "GetNextNumber"

Tom

:

You need to open a new Module (in main database window), paste the code into
there. save the module (basGetNextNumber would be a good name)

THEN go to your table and type GetNextNumber() into the default vlaue of
your field.

HTH

Rico

:

I got the follow message trying to save the table,
in "design view" "The expression you entered contains invalid syntax. You
may have entered an operand without an operator."
I cut and pasted the formula
Tom

:

I think this question has set a record for the number of times asked. Were I
smarter, I would save the answer in a text file so I could cut and paste and
not have to write it again (3rd time this week):

Here is a function that will give you the next number.

Function GetNextNumber as String
Dim strCurrDate as String
Dim varHighValue as Variant

strCurrDate = Format(Date, "yymmdd")
varHighValue = DMax("[MyField]", "MyTable", "Left([MyField], 6) = '" _
& strCurrDate & "'")
If IsNull(varHighValue) Then
GetNextNumber = strCurrDate & "001"
Else
GetNextNumber = =Format(CLng(Left(varHighValue,6))+1,"000000000")
End If
End Function

To use it, make it the Default Value of the text box where you display the
number
:

I need a way for one of my fields to change
incrementally as new records are created.
This field will always have 9 numbers max.
It must start with todays date in the
format 051117 and then 001
This should change to 002 for the next record
The date should also change;
i.e. at 11:59pm the last record is
051117052 at 12:00am it will automatically
change to 051118001
there will never be a "000" record.

Any thoughts would be greatly appreciated.

Tom
 
T

Tom

Well, let me tell you. Before I read your last
post, I got the number to work, however when
I click on my button that records the record
and puts me onto the next record, the
number stays the same and does not incrementaly
change.

Now, let me tell you where I am
forms design
tools
macros
visual basic
object browser
I've selected my database "ABLE DISPATCH"
below that is "Classes"
under that I see the following
global
basGetNextNumber
Form_ABLE Dispatch 3
Module 1

basGetNextNumber when selected
shows GetNextNumber under "Members of basGetNextNumber"

The number I initially want is showing up
i.e. todays date 051117001 (although without the "0" in front)
However, when I record the data, and go to the next
record, the same number shows up. It should
read 051117002

Tom


Klatuu said:
Okay.
Open the form in Design view where you have the control you want the number
to be in
Click the Code icon on the Toolbar. (it looks like a box with little blue,
red, and yellow balls on it.
The VB Editor will open.
The Caption at the top of the screen should have the name of your form in it.
Go to the top of the form module.
The two panes at the top should say (General) on the left and (Declarations)
on the right. Just below that there should be some option statments Like:
Option Compare Database
Option Explicit
etc.

Doesn't matter what they say, just trying to get you oriented.
Copy the code I sent and paste it just below the last Option statement, but
before any other code you see.

You will need to replace my made up names with the correct names for your
own objects.

Save it.
Close the VB Editor
On your form, right click on the text box where you want the number to
display.
Select Properties from the dropdown menu.
Look for the property named Default Value
Put this in the box next to it:
=GetNextNumber()
Save it.
Test it,
let me know what happens.




Tom said:
Forgive me, I'm stupid. I've never touch this before.
I need my hand held. I have the formula ready to
paste. I just need to know exactly "step, by step"
what to click on where to go.
I had to reset my puter to yesterday to get rid
of my stupidity.
Do you want me in "forms" or "tables"
Do you want me to select "tools" then "macros"
I don't know.
Tom

Klatuu said:
I believe that means it can't find the function GetNextNumber. Either you
spelled it incorrectly in the function or where you call it, or the function
is not where the form can see it.
Check your spelling, and if that is not it, tell me where you put the
function?

:

Klatuu,
Now it comes up with
#Name?
In the field of "Form View"

No syntax or other errors
Tom

:

typo on my part, sorry. Should be:

GetNextNumber = Format(CLng(Left(varHighValue,6))+1,"000000000")

It doesn't need to be in a standard module unless you plan to use it else
where. If it is for this form only, put it in the General section of your
form module.

:

Rico,
It gave me a syntax error
and highlighted

GetNextNumber = =Format(CLng(Left(varHighValue,6))+1,"000000000")

Then I clicked "OK" and highlighted in Yellow was:

Function GetNextNumber as String

I also noticed that when I went to save it, next to "General"
it changed from "Declarations" to "GetNextNumber"

Tom

:

You need to open a new Module (in main database window), paste the code into
there. save the module (basGetNextNumber would be a good name)

THEN go to your table and type GetNextNumber() into the default vlaue of
your field.

HTH

Rico

:

I got the follow message trying to save the table,
in "design view" "The expression you entered contains invalid syntax. You
may have entered an operand without an operator."
I cut and pasted the formula
Tom

:

I think this question has set a record for the number of times asked. Were I
smarter, I would save the answer in a text file so I could cut and paste and
not have to write it again (3rd time this week):

Here is a function that will give you the next number.

Function GetNextNumber as String
Dim strCurrDate as String
Dim varHighValue as Variant

strCurrDate = Format(Date, "yymmdd")
varHighValue = DMax("[MyField]", "MyTable", "Left([MyField], 6) = '" _
& strCurrDate & "'")
If IsNull(varHighValue) Then
GetNextNumber = strCurrDate & "001"
Else
GetNextNumber = =Format(CLng(Left(varHighValue,6))+1,"000000000")
End If
End Function

To use it, make it the Default Value of the text box where you display the
number
:

I need a way for one of my fields to change
incrementally as new records are created.
This field will always have 9 numbers max.
It must start with todays date in the
format 051117 and then 001
This should change to 002 for the next record
The date should also change;
i.e. at 11:59pm the last record is
051117052 at 12:00am it will automatically
change to 051118001
there will never be a "000" record.

Any thoughts would be greatly appreciated.

Tom
 
K

Klatuu

Is the text box where the number is bound to a field in the record source of
your form?
As far as the leading 0 goes, I suggest you leave it that way. If you
don't, it will be much harder to do the formatting, it will not sort
correctly.

Tom said:
Well, let me tell you. Before I read your last
post, I got the number to work, however when
I click on my button that records the record
and puts me onto the next record, the
number stays the same and does not incrementaly
change.

Now, let me tell you where I am
forms design
tools
macros
visual basic
object browser
I've selected my database "ABLE DISPATCH"
below that is "Classes"
under that I see the following
global
basGetNextNumber
Form_ABLE Dispatch 3
Module 1

basGetNextNumber when selected
shows GetNextNumber under "Members of basGetNextNumber"

The number I initially want is showing up
i.e. todays date 051117001 (although without the "0" in front)
However, when I record the data, and go to the next
record, the same number shows up. It should
read 051117002

Tom


Klatuu said:
Okay.
Open the form in Design view where you have the control you want the number
to be in
Click the Code icon on the Toolbar. (it looks like a box with little blue,
red, and yellow balls on it.
The VB Editor will open.
The Caption at the top of the screen should have the name of your form in it.
Go to the top of the form module.
The two panes at the top should say (General) on the left and (Declarations)
on the right. Just below that there should be some option statments Like:
Option Compare Database
Option Explicit
etc.

Doesn't matter what they say, just trying to get you oriented.
Copy the code I sent and paste it just below the last Option statement, but
before any other code you see.

You will need to replace my made up names with the correct names for your
own objects.

Save it.
Close the VB Editor
On your form, right click on the text box where you want the number to
display.
Select Properties from the dropdown menu.
Look for the property named Default Value
Put this in the box next to it:
=GetNextNumber()
Save it.
Test it,
let me know what happens.




Tom said:
Forgive me, I'm stupid. I've never touch this before.
I need my hand held. I have the formula ready to
paste. I just need to know exactly "step, by step"
what to click on where to go.
I had to reset my puter to yesterday to get rid
of my stupidity.
Do you want me in "forms" or "tables"
Do you want me to select "tools" then "macros"
I don't know.
Tom

:

I believe that means it can't find the function GetNextNumber. Either you
spelled it incorrectly in the function or where you call it, or the function
is not where the form can see it.
Check your spelling, and if that is not it, tell me where you put the
function?

:

Klatuu,
Now it comes up with
#Name?
In the field of "Form View"

No syntax or other errors
Tom

:

typo on my part, sorry. Should be:

GetNextNumber = Format(CLng(Left(varHighValue,6))+1,"000000000")

It doesn't need to be in a standard module unless you plan to use it else
where. If it is for this form only, put it in the General section of your
form module.

:

Rico,
It gave me a syntax error
and highlighted

GetNextNumber = =Format(CLng(Left(varHighValue,6))+1,"000000000")

Then I clicked "OK" and highlighted in Yellow was:

Function GetNextNumber as String

I also noticed that when I went to save it, next to "General"
it changed from "Declarations" to "GetNextNumber"

Tom

:

You need to open a new Module (in main database window), paste the code into
there. save the module (basGetNextNumber would be a good name)

THEN go to your table and type GetNextNumber() into the default vlaue of
your field.

HTH

Rico

:

I got the follow message trying to save the table,
in "design view" "The expression you entered contains invalid syntax. You
may have entered an operand without an operator."
I cut and pasted the formula
Tom

:

I think this question has set a record for the number of times asked. Were I
smarter, I would save the answer in a text file so I could cut and paste and
not have to write it again (3rd time this week):

Here is a function that will give you the next number.

Function GetNextNumber as String
Dim strCurrDate as String
Dim varHighValue as Variant

strCurrDate = Format(Date, "yymmdd")
varHighValue = DMax("[MyField]", "MyTable", "Left([MyField], 6) = '" _
& strCurrDate & "'")
If IsNull(varHighValue) Then
GetNextNumber = strCurrDate & "001"
Else
GetNextNumber = =Format(CLng(Left(varHighValue,6))+1,"000000000")
End If
End Function

To use it, make it the Default Value of the text box where you display the
number
:

I need a way for one of my fields to change
incrementally as new records are created.
This field will always have 9 numbers max.
It must start with todays date in the
format 051117 and then 001
This should change to 002 for the next record
The date should also change;
i.e. at 11:59pm the last record is
051117052 at 12:00am it will automatically
change to 051118001
there will never be a "000" record.

Any thoughts would be greatly appreciated.

Tom
 
T

Tom

Klatuu,
Man you are a patient person. Thank-you!
I kinda understand what you're saying and have
used the "wizard", however I need walked thru it.
I am so close but yet so far.
Do you want me in "design forms" to start?

Klatuu said:
Is the text box where the number is bound to a field in the record source of
your form?
As far as the leading 0 goes, I suggest you leave it that way. If you
don't, it will be much harder to do the formatting, it will not sort
correctly.

Tom said:
Well, let me tell you. Before I read your last
post, I got the number to work, however when
I click on my button that records the record
and puts me onto the next record, the
number stays the same and does not incrementaly
change.

Now, let me tell you where I am
forms design
tools
macros
visual basic
object browser
I've selected my database "ABLE DISPATCH"
below that is "Classes"
under that I see the following
global
basGetNextNumber
Form_ABLE Dispatch 3
Module 1

basGetNextNumber when selected
shows GetNextNumber under "Members of basGetNextNumber"

The number I initially want is showing up
i.e. todays date 051117001 (although without the "0" in front)
However, when I record the data, and go to the next
record, the same number shows up. It should
read 051117002

Tom


Klatuu said:
Okay.
Open the form in Design view where you have the control you want the number
to be in
Click the Code icon on the Toolbar. (it looks like a box with little blue,
red, and yellow balls on it.
The VB Editor will open.
The Caption at the top of the screen should have the name of your form in it.
Go to the top of the form module.
The two panes at the top should say (General) on the left and (Declarations)
on the right. Just below that there should be some option statments Like:
Option Compare Database
Option Explicit
etc.

Doesn't matter what they say, just trying to get you oriented.
Copy the code I sent and paste it just below the last Option statement, but
before any other code you see.

You will need to replace my made up names with the correct names for your
own objects.

Save it.
Close the VB Editor
On your form, right click on the text box where you want the number to
display.
Select Properties from the dropdown menu.
Look for the property named Default Value
Put this in the box next to it:
=GetNextNumber()
Save it.
Test it,
let me know what happens.




:

Forgive me, I'm stupid. I've never touch this before.
I need my hand held. I have the formula ready to
paste. I just need to know exactly "step, by step"
what to click on where to go.
I had to reset my puter to yesterday to get rid
of my stupidity.
Do you want me in "forms" or "tables"
Do you want me to select "tools" then "macros"
I don't know.
Tom

:

I believe that means it can't find the function GetNextNumber. Either you
spelled it incorrectly in the function or where you call it, or the function
is not where the form can see it.
Check your spelling, and if that is not it, tell me where you put the
function?

:

Klatuu,
Now it comes up with
#Name?
In the field of "Form View"

No syntax or other errors
Tom

:

typo on my part, sorry. Should be:

GetNextNumber = Format(CLng(Left(varHighValue,6))+1,"000000000")

It doesn't need to be in a standard module unless you plan to use it else
where. If it is for this form only, put it in the General section of your
form module.

:

Rico,
It gave me a syntax error
and highlighted

GetNextNumber = =Format(CLng(Left(varHighValue,6))+1,"000000000")

Then I clicked "OK" and highlighted in Yellow was:

Function GetNextNumber as String

I also noticed that when I went to save it, next to "General"
it changed from "Declarations" to "GetNextNumber"

Tom

:

You need to open a new Module (in main database window), paste the code into
there. save the module (basGetNextNumber would be a good name)

THEN go to your table and type GetNextNumber() into the default vlaue of
your field.

HTH

Rico

:

I got the follow message trying to save the table,
in "design view" "The expression you entered contains invalid syntax. You
may have entered an operand without an operator."
I cut and pasted the formula
Tom

:

I think this question has set a record for the number of times asked. Were I
smarter, I would save the answer in a text file so I could cut and paste and
not have to write it again (3rd time this week):

Here is a function that will give you the next number.

Function GetNextNumber as String
Dim strCurrDate as String
Dim varHighValue as Variant

strCurrDate = Format(Date, "yymmdd")
varHighValue = DMax("[MyField]", "MyTable", "Left([MyField], 6) = '" _
& strCurrDate & "'")
If IsNull(varHighValue) Then
GetNextNumber = strCurrDate & "001"
Else
GetNextNumber = =Format(CLng(Left(varHighValue,6))+1,"000000000")
End If
End Function

To use it, make it the Default Value of the text box where you display the
number
:

I need a way for one of my fields to change
incrementally as new records are created.
This field will always have 9 numbers max.
It must start with todays date in the
format 051117 and then 001
This should change to 002 for the next record
The date should also change;
i.e. at 11:59pm the last record is
051117052 at 12:00am it will automatically
change to 051118001
there will never be a "000" record.

Any thoughts would be greatly appreciated.

Tom
 
T

Tom

ALSO, The record label, Also the name of the field, is "RUN NUMBER"
(with the space). That's how I put it in the formula.

Klatuu said:
Is the text box where the number is bound to a field in the record source of
your form?
As far as the leading 0 goes, I suggest you leave it that way. If you
don't, it will be much harder to do the formatting, it will not sort
correctly.

Tom said:
Well, let me tell you. Before I read your last
post, I got the number to work, however when
I click on my button that records the record
and puts me onto the next record, the
number stays the same and does not incrementaly
change.

Now, let me tell you where I am
forms design
tools
macros
visual basic
object browser
I've selected my database "ABLE DISPATCH"
below that is "Classes"
under that I see the following
global
basGetNextNumber
Form_ABLE Dispatch 3
Module 1

basGetNextNumber when selected
shows GetNextNumber under "Members of basGetNextNumber"

The number I initially want is showing up
i.e. todays date 051117001 (although without the "0" in front)
However, when I record the data, and go to the next
record, the same number shows up. It should
read 051117002

Tom


Klatuu said:
Okay.
Open the form in Design view where you have the control you want the number
to be in
Click the Code icon on the Toolbar. (it looks like a box with little blue,
red, and yellow balls on it.
The VB Editor will open.
The Caption at the top of the screen should have the name of your form in it.
Go to the top of the form module.
The two panes at the top should say (General) on the left and (Declarations)
on the right. Just below that there should be some option statments Like:
Option Compare Database
Option Explicit
etc.

Doesn't matter what they say, just trying to get you oriented.
Copy the code I sent and paste it just below the last Option statement, but
before any other code you see.

You will need to replace my made up names with the correct names for your
own objects.

Save it.
Close the VB Editor
On your form, right click on the text box where you want the number to
display.
Select Properties from the dropdown menu.
Look for the property named Default Value
Put this in the box next to it:
=GetNextNumber()
Save it.
Test it,
let me know what happens.




:

Forgive me, I'm stupid. I've never touch this before.
I need my hand held. I have the formula ready to
paste. I just need to know exactly "step, by step"
what to click on where to go.
I had to reset my puter to yesterday to get rid
of my stupidity.
Do you want me in "forms" or "tables"
Do you want me to select "tools" then "macros"
I don't know.
Tom

:

I believe that means it can't find the function GetNextNumber. Either you
spelled it incorrectly in the function or where you call it, or the function
is not where the form can see it.
Check your spelling, and if that is not it, tell me where you put the
function?

:

Klatuu,
Now it comes up with
#Name?
In the field of "Form View"

No syntax or other errors
Tom

:

typo on my part, sorry. Should be:

GetNextNumber = Format(CLng(Left(varHighValue,6))+1,"000000000")

It doesn't need to be in a standard module unless you plan to use it else
where. If it is for this form only, put it in the General section of your
form module.

:

Rico,
It gave me a syntax error
and highlighted

GetNextNumber = =Format(CLng(Left(varHighValue,6))+1,"000000000")

Then I clicked "OK" and highlighted in Yellow was:

Function GetNextNumber as String

I also noticed that when I went to save it, next to "General"
it changed from "Declarations" to "GetNextNumber"

Tom

:

You need to open a new Module (in main database window), paste the code into
there. save the module (basGetNextNumber would be a good name)

THEN go to your table and type GetNextNumber() into the default vlaue of
your field.

HTH

Rico

:

I got the follow message trying to save the table,
in "design view" "The expression you entered contains invalid syntax. You
may have entered an operand without an operator."
I cut and pasted the formula
Tom

:

I think this question has set a record for the number of times asked. Were I
smarter, I would save the answer in a text file so I could cut and paste and
not have to write it again (3rd time this week):

Here is a function that will give you the next number.

Function GetNextNumber as String
Dim strCurrDate as String
Dim varHighValue as Variant

strCurrDate = Format(Date, "yymmdd")
varHighValue = DMax("[MyField]", "MyTable", "Left([MyField], 6) = '" _
& strCurrDate & "'")
If IsNull(varHighValue) Then
GetNextNumber = strCurrDate & "001"
Else
GetNextNumber = =Format(CLng(Left(varHighValue,6))+1,"000000000")
End If
End Function

To use it, make it the Default Value of the text box where you display the
number
:

I need a way for one of my fields to change
incrementally as new records are created.
This field will always have 9 numbers max.
It must start with todays date in the
format 051117 and then 001
This should change to 002 for the next record
The date should also change;
i.e. at 11:59pm the last record is
051117052 at 12:00am it will automatically
change to 051118001
there will never be a "000" record.

Any thoughts would be greatly appreciated.

Tom
 
T

Tom

Thought you might like to know the following:
Database: ABLE DISPATCH (with space)
Table: ABLE_Table1 (no spaces)
Form: ABLE Dispatch 3 (with 2 spaces)
Under Module there is
basGetNextNumber
Module1
There are no reports, queiries, or macros

Here is the formula as it appears:
Option Compare Database

Function GetNextNumber() As String
Dim strCurrDate As String
Dim varHighValue As Variant
strCurrDate = Format(Date, "yymmdd")
varHighValue = DMax("[RUN NUMBER]", "ABLE_Table1", "Left([RUN NUMBER], 6) =
'" _
& strCurrDate & "'")
If IsNull(varHighValue) Then
GetNextNumber = strCurrDate & "001"
Else
GetNextNumber = Format(CLng(Left(varHighValue, 6)) + 1, "000000000")
End If
End Function



Tom said:
ALSO, The record label, Also the name of the field, is "RUN NUMBER"
(with the space). That's how I put it in the formula.

Klatuu said:
Is the text box where the number is bound to a field in the record source of
your form?
As far as the leading 0 goes, I suggest you leave it that way. If you
don't, it will be much harder to do the formatting, it will not sort
correctly.

Tom said:
Well, let me tell you. Before I read your last
post, I got the number to work, however when
I click on my button that records the record
and puts me onto the next record, the
number stays the same and does not incrementaly
change.

Now, let me tell you where I am
forms design
tools
macros
visual basic
object browser
I've selected my database "ABLE DISPATCH"
below that is "Classes"
under that I see the following
global
basGetNextNumber
Form_ABLE Dispatch 3
Module 1

basGetNextNumber when selected
shows GetNextNumber under "Members of basGetNextNumber"

The number I initially want is showing up
i.e. todays date 051117001 (although without the "0" in front)
However, when I record the data, and go to the next
record, the same number shows up. It should
read 051117002

Tom


:

Okay.
Open the form in Design view where you have the control you want the number
to be in
Click the Code icon on the Toolbar. (it looks like a box with little blue,
red, and yellow balls on it.
The VB Editor will open.
The Caption at the top of the screen should have the name of your form in it.
Go to the top of the form module.
The two panes at the top should say (General) on the left and (Declarations)
on the right. Just below that there should be some option statments Like:
Option Compare Database
Option Explicit
etc.

Doesn't matter what they say, just trying to get you oriented.
Copy the code I sent and paste it just below the last Option statement, but
before any other code you see.

You will need to replace my made up names with the correct names for your
own objects.

Save it.
Close the VB Editor
On your form, right click on the text box where you want the number to
display.
Select Properties from the dropdown menu.
Look for the property named Default Value
Put this in the box next to it:
=GetNextNumber()
Save it.
Test it,
let me know what happens.




:

Forgive me, I'm stupid. I've never touch this before.
I need my hand held. I have the formula ready to
paste. I just need to know exactly "step, by step"
what to click on where to go.
I had to reset my puter to yesterday to get rid
of my stupidity.
Do you want me in "forms" or "tables"
Do you want me to select "tools" then "macros"
I don't know.
Tom

:

I believe that means it can't find the function GetNextNumber. Either you
spelled it incorrectly in the function or where you call it, or the function
is not where the form can see it.
Check your spelling, and if that is not it, tell me where you put the
function?

:

Klatuu,
Now it comes up with
#Name?
In the field of "Form View"

No syntax or other errors
Tom

:

typo on my part, sorry. Should be:

GetNextNumber = Format(CLng(Left(varHighValue,6))+1,"000000000")

It doesn't need to be in a standard module unless you plan to use it else
where. If it is for this form only, put it in the General section of your
form module.

:

Rico,
It gave me a syntax error
and highlighted

GetNextNumber = =Format(CLng(Left(varHighValue,6))+1,"000000000")

Then I clicked "OK" and highlighted in Yellow was:

Function GetNextNumber as String

I also noticed that when I went to save it, next to "General"
it changed from "Declarations" to "GetNextNumber"

Tom

:

You need to open a new Module (in main database window), paste the code into
there. save the module (basGetNextNumber would be a good name)

THEN go to your table and type GetNextNumber() into the default vlaue of
your field.

HTH

Rico

:

I got the follow message trying to save the table,
in "design view" "The expression you entered contains invalid syntax. You
may have entered an operand without an operator."
I cut and pasted the formula
Tom

:

I think this question has set a record for the number of times asked. Were I
smarter, I would save the answer in a text file so I could cut and paste and
not have to write it again (3rd time this week):

Here is a function that will give you the next number.

Function GetNextNumber as String
Dim strCurrDate as String
Dim varHighValue as Variant

strCurrDate = Format(Date, "yymmdd")
varHighValue = DMax("[MyField]", "MyTable", "Left([MyField], 6) = '" _
& strCurrDate & "'")
If IsNull(varHighValue) Then
GetNextNumber = strCurrDate & "001"
Else
GetNextNumber = =Format(CLng(Left(varHighValue,6))+1,"000000000")
End If
End Function

To use it, make it the Default Value of the text box where you display the
number
:

I need a way for one of my fields to change
incrementally as new records are created.
This field will always have 9 numbers max.
It must start with todays date in the
format 051117 and then 001
This should change to 002 for the next record
The date should also change;
i.e. at 11:59pm the last record is
051117052 at 12:00am it will automatically
change to 051118001
there will never be a "000" record.

Any thoughts would be greatly appreciated.

Tom
 

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

Similar Threads

Formula ? 30
tp Sequential Counting? 0
Find Records Between Date/Time 2
Previous Date in a Query 1
Update query with date criteria 3
Most recent date prior to test date. 2
first record query 4
Validation Rule 2

Top