473,382 Members | 1,225 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,382 software developers and data experts.

Auto numbering oddity

Hi,

The db that's used as our corporate non conformace register, uses a NCF
numbering system based on yy-xxxx. The yy is calculated using the year
(sorry seems a bit obvious) and the xxxx bit is calculated for the next
new NCF by adding 1 onto the previously recorded number. What I want
to do is enter the main table and manually add a higher number so that
when a new procedure is implemented, we are starting from a known entry
# and date. What I cannot work out, is even though I can enter the
main table and add the number I want, when using the form to then make
a new entry, the form's not working off the number I've ented. By
that, as it stand now, if a new entry is 06-1001, the next one will be
06-1002. If I wanted to manually add one as 06-1500, the forms not
incrementing to 06-1501. Any ideas? The codes below if it's any help.

Private Sub New_NCR_Click()

Dim rst, NCRNumber, strcriteria, DDate, ddatestart, ddateend

Dim stDocName As String
Dim stLinkCriteria As String
Dim dbs As Database
DDate = Format(Date, "yy")
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("NCR_Table New", dbOpenDynaset)

For NCRNumber = 1 To 9999
strcriteria = "[NCR] = " & "'" & DDate & "-" & Format([NCRNumber],
"0000") & "'"
With rst
.FindFirst strcriteria
If .NoMatch Then
Exit For
End If
End With
Next NCRNumber

stDocName = "NCF Form"
DoCmd.OpenForm stDocName, acNormal, , , acFormAdd
Forms![NCF Form]![NCR] = DDate & "-" & Format(NCRNumber, "0000")
Forms![NCF Form]![Date Initiated] = Date
DoCmd.Save
Forms![NCF Form]![Type].SetFocus

End Sub

Oct 13 '06 #1
7 1481
somebody went to the trouble of writing the for/next loop to
prevent having gaps in your ncr numbers. It obviously works very
well.

replace it with the following 1 line of code
NCRNumber = nz(dmax("NCR","NCR_Table New",
left([NCR],2 = """ & DDate & """)"

insert it after the NEXT NCRnumber line. so you could go back to
the old code next year.
"Stinky Pete" <Pe**********@symbionhealth.comwrote in
news:11**********************@k70g2000cwa.googlegr oups.com:
Hi,

The db that's used as our corporate non conformace register,
uses a NCF numbering system based on yy-xxxx. The yy is
calculated using the year (sorry seems a bit obvious) and the
xxxx bit is calculated for the next new NCF by adding 1 onto
the previously recorded number. What I want to do is enter
the main table and manually add a higher number so that when a
new procedure is implemented, we are starting from a known
entry # and date. What I cannot work out, is even though I
can enter the main table and add the number I want, when using
the form to then make a new entry, the form's not working off
the number I've ented. By that, as it stand now, if a new
entry is 06-1001, the next one will be 06-1002. If I wanted
to manually add one as 06-1500, the forms not incrementing to
06-1501. Any ideas? The codes below if it's any help.

Private Sub New_NCR_Click()

Dim rst, NCRNumber, strcriteria, DDate, ddatestart, ddateend

Dim stDocName As String
Dim stLinkCriteria As String
Dim dbs As Database
DDate = Format(Date, "yy")
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("NCR_Table New", dbOpenDynaset)

For NCRNumber = 1 To 9999
strcriteria = "[NCR] = " & "'" & DDate & "-" &
Format([NCRNumber],
"0000") & "'"
With rst
.FindFirst strcriteria
If .NoMatch Then
Exit For
End If
End With
Next NCRNumber

stDocName = "NCF Form"
DoCmd.OpenForm stDocName, acNormal, , , acFormAdd
Forms![NCF Form]![NCR] = DDate & "-" & Format(NCRNumber,
"0000") Forms![NCF Form]![Date Initiated] = Date
DoCmd.Save
Forms![NCF Form]![Type].SetFocus

End Sub



--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Oct 13 '06 #2
On 13 Oct 2006 01:42:20 GMT, Bob Quintal <rq******@sPAmpatico.ca>
wrote:

You probably meant: it obviously works very slowly.
The average number of comparisons would be n/2, or likely even greater
than that in the real world when the lower values have been filled in.

Amazing that some people still refuse to use indexes (the powerful
Seek method).

For some applications, expecially with a lot of disconnected logic, I
use a "TakeANumber" sproc which takes its value from a table with
TableName / NextNumberToUse records.

-Tom.
>somebody went to the trouble of writing the for/next loop to
prevent having gaps in your ncr numbers. It obviously works very
well.
<Clip>

Oct 13 '06 #3
Tom van Stiphout <no*************@cox.netwrote in
news:9l********************************@4ax.com:
You probably meant: it obviously works very slowly.
The average number of comparisons would be n/2, or likely even
greater than that in the real world when the lower values have
been filled in.

Amazing that some people still refuse to use indexes (the powerful
Seek method).

For some applications, expecially with a lot of disconnected
logic, I use a "TakeANumber" sproc which takes its value from a
table with TableName / NextNumberToUse records.
You can find the gaps with SQL without needing to walk through the
whole table.

Indeed, I've never done anything like this except with SQL.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Oct 13 '06 #4
Tom van Stiphout <no*************@cox.netwrote in
news:9l********************************@4ax.com:
On 13 Oct 2006 01:42:20 GMT, Bob Quintal
<rq******@sPAmpatico.cawrote:

You probably meant: it obviously works very slowly.
I was being somewhat facetious.
The average number of comparisons would be n/2, or likely even
greater than that in the real world when the lower values have
been filled in.
Worse, assuming that the recordset is returning the PK of the
table, and the numbers are in order.the average number of
comparisons would be n, not n/2. The whole object of such a routine
is to fill in any gaps created by a user abandoning the creation of
a record, as is often seen with autonumbers.

In normal situation if a gap occurs, it will be the second from
highest number.
>
Amazing that some people still refuse to use indexes (the
powerful Seek method).
Tell the world how to seek for the number not in the index, please.
For some applications, expecially with a lot of disconnected
logic, I use a "TakeANumber" sproc which takes its value from
a table with TableName / NextNumberToUse records.

-Tom.
This is also my preferred method. Although a select top 1 PK order
by PK descending works pretty well too, but again can leave gaps in
the numbering.
>

>>somebody went to the trouble of writing the for/next loop to
prevent having gaps in your ncr numbers. It obviously works
very well.
<Clip>


--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Oct 13 '06 #5
"David W. Fenton" <XX*******@dfenton.com.invalidwrote in
news:Xn**********************************@127.0.0. 1:
Tom van Stiphout <no*************@cox.netwrote in
news:9l********************************@4ax.com:
>You probably meant: it obviously works very slowly.
The average number of comparisons would be n/2, or likely
even greater than that in the real world when the lower
values have been filled in.

Amazing that some people still refuse to use indexes (the
powerful Seek method).

For some applications, expecially with a lot of disconnected
logic, I use a "TakeANumber" sproc which takes its value from
a table with TableName / NextNumberToUse records.

You can find the gaps with SQL without needing to walk through
the whole table.

Indeed, I've never done anything like this except with SQL.
Please supply a sample SQL statement to do so.
--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Oct 13 '06 #6
Bob Quintal <rq******@sPAmpatico.cawrote in
news:Xn**********************@66.150.105.47:
"David W. Fenton" <XX*******@dfenton.com.invalidwrote in
news:Xn**********************************@127.0.0. 1:
>Tom van Stiphout <no*************@cox.netwrote in
news:9l********************************@4ax.com :
>>You probably meant: it obviously works very slowly.
The average number of comparisons would be n/2, or likely
even greater than that in the real world when the lower
values have been filled in.

Amazing that some people still refuse to use indexes (the
powerful Seek method).

For some applications, expecially with a lot of disconnected
logic, I use a "TakeANumber" sproc which takes its value from
a table with TableName / NextNumberToUse records.

You can find the gaps with SQL without needing to walk through
the whole table.

Indeed, I've never done anything like this except with SQL.

Please supply a sample SQL statement to do so.
Non-equi self-join on the ID field. Find the Min() of the first one
lacking having a Null value in the field N+1.

This will give you all the IDs where there isn't an ID+1 value:

SELECT tblMain.ID
FROM tblMain LEFT JOIN tblMain AS NextIDTable ON tblMain.ID =
NextIDTable.ID+1 WHERE NextIDTable.ID Is Null;

Then take the Min() of the first column and add 1 to it:

SELECT Min(tblMain.ID) + 1 As NextIDToFillGap
FROM tblMain LEFT JOIN tblMain AS NextIDTable ON tblMain.ID =
NextIDTable.ID+1 WHERE NextIDTable.ID Is Null;

That will give you the next available unused ID number.

Many people don't know you can do non-equi joins in Access. You
can't do them in the QBE, but if you create it as an equi-join in
the QBE, you can then edit it in SQL view to change it to any type
of non-equi join you like.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Oct 14 '06 #7
"David W. Fenton" <XX*******@dfenton.com.invalidwrote in
news:Xn**********************************@127.0.0. 1:
Bob Quintal <rq******@sPAmpatico.cawrote in
news:Xn**********************@66.150.105.47:
>"David W. Fenton" <XX*******@dfenton.com.invalidwrote in
news:Xn**********************************@127.0.0 .1:
>>Tom van Stiphout <no*************@cox.netwrote in
news:9l********************************@4ax.co m:

You probably meant: it obviously works very slowly.
The average number of comparisons would be n/2, or likely
even greater than that in the real world when the lower
values have been filled in.

Amazing that some people still refuse to use indexes (the
powerful Seek method).

For some applications, expecially with a lot of
disconnected logic, I use a "TakeANumber" sproc which takes
its value from a table with TableName / NextNumberToUse
records.

You can find the gaps with SQL without needing to walk
through the whole table.

Indeed, I've never done anything like this except with SQL.

Please supply a sample SQL statement to do so.

Non-equi self-join on the ID field. Find the Min() of the
first one lacking having a Null value in the field N+1.

This will give you all the IDs where there isn't an ID+1
value:

SELECT tblMain.ID
FROM tblMain LEFT JOIN tblMain AS NextIDTable ON tblMain.ID =
NextIDTable.ID+1 WHERE NextIDTable.ID Is Null;

Then take the Min() of the first column and add 1 to it:

SELECT Min(tblMain.ID) + 1 As NextIDToFillGap
FROM tblMain LEFT JOIN tblMain AS NextIDTable ON tblMain.ID =
NextIDTable.ID+1 WHERE NextIDTable.ID Is Null;

That will give you the next available unused ID number.

Many people don't know you can do non-equi joins in Access.
You can't do them in the QBE, but if you create it as an
equi-join in the QBE, you can then edit it in SQL view to
change it to any type of non-equi join you like.
interesting technique, and it makes sense.

As to non-equi joins, you can also use the old syntax of using
the where clause to join the tables.
The one drawback to editing the join equation is that if for any
reason the query gets opened in the design mode, it's trash.

I spend more time in the SQL window than in the qbe grid.these
days, I just wish (acc 97) it had find and replace and an insert
field name utility in the SQL window..

I suppose I could build a form.
--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Oct 14 '06 #8

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

Similar topics

8
by: Steven Burn | last post by:
I'm curious, I've written a very simple PIS (personal info store) that allows one to store whatever they wish..... the problem is, when one deletes an entry, the auto-numbering isn't corrected to...
5
by: Charles McCaffery | last post by:
I have written a database with auto-numbering and now wish to remove alkl of my test data and set the auto-numbering back to one. How do I do this please? Charles McCaffery.
0
by: MJ | last post by:
I am setting up a database and want my auto numbering on a table to include letters. It works find until I hit 10 then it puts the 1 before the letters. Here is what I am using for format: ...
6
by: MJ | last post by:
No one answered my original e-mail--it probably wasn't clear. I am hoping this makes the question a little clearer. Is it possible to combine both letters and numbers in an auto number? I can't...
6
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I...
3
by: Chris | last post by:
Before I started to create table, etc to track unique form field record number assigments I thought I'd check to see if there is now a better way to do this in .NET. I have a parent form (table)...
0
by: saraDotNet | last post by:
Hi, I'v Two Questions: 1-Is there a way to make an auto numbering avalible in vb.net form textbox as the one in Access db columns when we set the datatype as autonumbering?? 2- I'm working on a...
6
by: orit | last post by:
I have a word document that contains a table. The table has 2 columns and hundreds of rows. I want to number the items in the table in the following way: In the first column, each cell will contain...
0
by: jimratajski | last post by:
Can anyone tell me how to automate page numbering of spawned page templates in Acrobat? I have a number of forms containing hidden page templates that I would like to be auto numbered as they are...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.