473,414 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Sequential numbers

I recently posted a message asking for help with
sequential numbers. I want to create an autonnumber
reference number that reverts back to 1 at the start of
each year. GlenAppleton gave me some code and I thought I
had it working but I don't. When I create a new record
nothing happens in the control CommDocNbrtxt where the
number should appear.
Here is my complete code, can anyone help?
If you read this Glen sorry to post again but I wasn't
sure if you would go back to check my last message

Option Compare Database
Function GetDocIndex() As String

Dim rsDocs As DAO.Recordset
Dim intDocIdx As Integer
Dim strLastIdx As String, strNewIdx As String, strSQL
As String

' Get the last index for this year
strSQL = "SELECT Max([CommDocNbrtxt]) As
[LastDocIdx] " & _
"FROM [tblDocGroupLists] " & _
"WHERE (Right([CommDocNbrtxt], 2) = '" & _
Right(CStr(Year(Date)), 2) & "');"
Set rsDocs = CurrentDb.OpenRecordset(strSQL)
With rsDocs
If Not .RecordCount = 0 Then
strLastIdx = .Fields("LastDocIdx").Value
.Close
'End With
Set rsDocs = Nothing

' Convert last index to integer or leave as zero
If Not strLastIdx = "" Then intDocIdx = CInt
(strLastIdx)

' Increment the index
intDocIdx = intDocIdx + 1

' Append the 2 digit year as decimal value
strNewIdx = intDocIdx & "." & Right(CStr(Year(Date)),
2)

' Return the new index
GetDocIndex = strNewIdx
End If
End With
End Function

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.CommDocNbrtxt.Value = "" Then
Me.CommDocNbrtxt.Value = GetDocIndex
End If

End Sub
TIA
Tony
Nov 12 '05 #1
2 3394
"Tony Williams" <to***********@thecapitalpartnership.co.uk> wrote in message
news:bl**********@sparta.btinternet.com...
I recently posted a message asking for help with
sequential numbers. I want to create an autonnumber
reference number that reverts back to 1 at the start of
each year. GlenAppleton gave me some code and I thought I
had it working but I don't. When I create a new record
nothing happens in the control CommDocNbrtxt where the
number should appear. [snip] Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.CommDocNbrtxt.Value = "" Then
Me.CommDocNbrtxt.Value = GetDocIndex
End If

End Sub


Unless you allow them and set them as the default it is unlikely that the value
of CommDocNbrtxt on a new record is "". It is probably Null. This test will
catch either...

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Len(Nz(Me.CommDocNbrtxt, "")) = 0 Then
Me.CommDocNbrtxt.Value = GetDocIndex
End If

End Sub
Nov 12 '05 #2
Thanks Rick I'll try that
Tony
"Rick Brandt" <rv********@sbcglobal.net> wrote in message
news:bl************@ID-98015.news.uni-berlin.de...
"Tony Williams" <to***********@thecapitalpartnership.co.uk> wrote in message news:bl**********@sparta.btinternet.com...
I recently posted a message asking for help with
sequential numbers. I want to create an autonnumber
reference number that reverts back to 1 at the start of
each year. GlenAppleton gave me some code and I thought I
had it working but I don't. When I create a new record
nothing happens in the control CommDocNbrtxt where the
number should appear. [snip]
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.CommDocNbrtxt.Value = "" Then
Me.CommDocNbrtxt.Value = GetDocIndex
End If

End Sub


Unless you allow them and set them as the default it is unlikely that the

value of CommDocNbrtxt on a new record is "". It is probably Null. This test will catch either...

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Len(Nz(Me.CommDocNbrtxt, "")) = 0 Then
Me.CommDocNbrtxt.Value = GetDocIndex
End If

End Sub

Nov 12 '05 #3

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

Similar topics

6
by: Jenn L | last post by:
I have a database that is pre-populated with sequential part numbers. As people reserve the parts I update a flag to show the # is no longer available. Now they want the ability to take out a...
5
by: Lapchien | last post by:
I have list of numbers in a table (originally from autonumber in a different database) from 1 to 1,000,000. The list is not in sequential order - there are loads of numbers missing. How can I...
14
by: amywolfie | last post by:
Hi All: I know this is simple, but I just can't seem to get there: I need to sort a table by a text field (txtDescription), then assign sequential numbers to the field SEQUENCE in table. ...
2
by: Mike Kingscott | last post by:
Hi all, I'd building an app that posts to a web service. One of the things that is required in the soap header is a sequential number appended to a ref, i.e. "IGI1001", "IGI1002", etc. ...
4
by: Bruce | last post by:
Surely someone has done this before, and I am guessing there is a simple solution that is eluding me. I have a simple report based on a recordset. For each record there is a field (RecNum) that...
1
maxamis4
by: maxamis4 | last post by:
Hello folks, I have two forms a parent form and a subform. The parent form is an unbound form while the subform is a form that contains all a list of what I like to call 'in stock ' phone...
6
by: jtidwell | last post by:
I am developing a Work Order Database for my job. I have a combo box with "Contract Numbers" to select from. When you select on any Contract Number I need a new "Work Order Number" to appear. There...
3
by: Finomosec | last post by:
Hi, i have a table of number-objects with beginning and endnr: 10-15 16-20 25-30 32-32 35-35 36-36 37-40
5
by: p3rk3le | last post by:
So, I'm about to do a sequential search on a table (n contents) of random numbers. I have to print the average between the number of comparisons and the contents of the table (n) and the...
9
by: Axxe | last post by:
I have searched high and low for cogent, well-explained coding to complete a project on which I have spent six months of work. I stumbled across something on this site that is close to what I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.