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

Field calcuation with an included yy

Hi,

I work in a manufacturing environment that needs to record non
conformances (NCF) against goods or processes. At the moment, QA can
open a form to automatically generate a new NCF number each time the
"New NCF" button is pressed on the main form. This number is in the
format yy-xxxx (see the code below). Each day we need to generate a
list of NCF numbers for manufacturing so that night shift can allocate
an NCF as necessary but this is done manually in Excel, not the
database. What I want to do is generate a report that at the end of
the day provides a lsit of about 10 new NCF numbers calcuated from the
last NCF number entered that day. It is not an option to allow
manufacturing access to the db.

What I was thinking of doing was generating a report that uses the code
below to make the first new number (one above the last entry) in a
field and then add 1 to this number etc up to the 10, via a new text
field or the like. The unsed manually generated numbers are not
entered into the db, so there's no chance of duplication when morning
shift comes in the next day. Anyway, if anyone can show me how to add
one to the highest number in the NCR field and not worry about the
"yy-" in the front of the field, please feel free to respond.

Regards,
Peter ;-)

Private Sub Form_Load()

Dim rst, NCRNumber, strcriteria, ddate, ddatestart, ddateend

Dim stDocName As String
Dim stLinkCriteria As String
Dim dbs As Database
ddate = Format(Date, "yy")
'ddatestart = ddate & "-" & Format(1, "0000")
'ddateend = ddate & "-" & "9999"
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 Manual Numbers"
DoCmd.OpenForm stDocName, acNormal, , , acFormAdd
Forms![NCF Manual Numbers]![NCR] = ddate & "-" & Format(NCRNumber,
"0000")
'Forms![NCF Manual Numbers]![Date Initiated] = Date

End Sub

Jun 27 '06 #1
3 1210
Read, drink, be merry... Someone has already solved this problem for
you...

http://www.mvps.org/access/strings/str0007.htm

Jun 27 '06 #2

pi********@hotmail.com wrote:
Read, drink, be merry... Someone has already solved this problem for
you...

http://www.mvps.org/access/strings/str0007.htm


Hi,

I did read, and got very merry - well sort of. Anyway, I get the gist
of what you're saying, with two following questions. The table has NCF
numbers from 4003-7854 (ish) with no preceeding yy- option and this
solution does not appear to work with the existing yy- formated numbers
unless the 4000-7000 numbers are deleted from the table (which I can't
do for traceability). The second quesiton, how do you get the leading
0 to remain in the field. Currently one of the higest numbers is
06-0895, but this funtion changes it to 06-865.

Hope to hear back,

Peter ;-)

Jun 27 '06 #3
Your problem is that you have a data type number, and you need data
type text. A data type number will never have preceding zeroes.

I once had the same problem with preceding zeros, and the number of
preceding zeros varied depending on which table required such a
number. So I wrote a function that took two arguments: the number in
question and the total number of characters required (which in your
case is 4).

Function addzeros(lngNumber as long, _
intDesiredLength as integer )strNewTextNumber as string
dim intCurrentLength as integer
dim strTextNumber as string

'make the number into a text string
strTextNumber = lngNumber

'find it's length
intCurrentLength = len(strTextNumber)

'loop adding zeros until the desired number of zeros are added
do while intCurrentLength < intDesiredLength
strTextNumber = "0" & strTextnumber
intCurrentLength = len(strTextNumber)
loop

addzeros = strNewTextNumber
End Function
On 26 Jun 2006 23:09:42 -0700, "Stinky Pete"
<Pe**********@symbionhealth.com> wrote:

pi********@hotmail.com wrote:
Read, drink, be merry... Someone has already solved this problem for
you...

http://www.mvps.org/access/strings/str0007.htm


Hi,

I did read, and got very merry - well sort of. Anyway, I get the gist
of what you're saying, with two following questions. The table has NCF
numbers from 4003-7854 (ish) with no preceeding yy- option and this
solution does not appear to work with the existing yy- formated numbers
unless the 4000-7000 numbers are deleted from the table (which I can't
do for traceability). The second quesiton, how do you get the leading
0 to remain in the field. Currently one of the higest numbers is
06-0895, but this funtion changes it to 06-865.

Hope to hear back,

Peter ;-)

Jun 27 '06 #4

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

Similar topics

10
by: Andres Eduardo Hernando | last post by:
Hi, I'm not entirely sure this is the right group to ask this question, but I saw a similar one above, and the group's charter is not clear enough about it, so, here I go: ;) What is the...
2
by: PMB | last post by:
Thank you in advance for any and all assistance. I'm trying to input data from strings to a memo field. I would like to know how to check first to see if there is text there currently and if so...
10
by: MLH | last post by:
I have an A97 table with a Yes/No field named TowJob and a form bound to that table. The TowJob control on the form is bound to the same field. It is an option group with Yes and No bttns valued...
4
by: Deborah V. Gardner | last post by:
I have a multi-user database in Access 2000. The back end is on the server and the front end is on each machine. The user will go to a field (defined as data type Memo) and make some changes. Then...
6
by: Richard | last post by:
Which way would you guys recommened to best parse a multiline file which contains two fields seperated by a tab. In this case its the linux/proc/filesystems file a sample of which I have included...
3
by: travellinman | last post by:
Hi, I'm trying to combine the text in two original fields and paste them into another 3rd field on a form, but the problem is that there are leading zeros in both original fields, which access does...
4
by: gitimaya | last post by:
hi can someone help me. I have two talbed. In one table (A)a field is having numbers like 111,222,333(field name (data"). In another table I have a field which has abc111222333xxx(B)(field name...
11
by: radink | last post by:
Hey All, I have a report that I would like to show a word on based on if a field is checked in a form. For example. The form has a check box called Fee. If that is checked, I want the word Paid...
6
by: nina01 | last post by:
Hi everybody!! I'm actually trying to construct a compiler with flex and bison. But when I try to compile the"lex.yy.c" file on cygwin I keep having this error: $gcc -c lex.yy.c In file...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
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...

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.