Don't know if this is possible
Hello,
I'm developing a program for a small non profit association.
I have this issue that I need it to do, but 1) I have no idea if it can be done 2) no idea how to do it (sort of).
This database deals with cats.
I have a table of Breeds and abreiviations
a Table of colors and abreiviations
a Table of Patterns and abreiviations
and a Table of Sexes with a corresponding number.
what I would like it to do:
The user inputs the information above about a cat through a series of combo boxes on a form, (I know how to display 1 value and store another), thats fairly straight forward.
Here's the tricky part.
As the user selects from the boxes I need it to automatically fill in another Field with the corresponding stored values, in order (this becomes part of the registration number).
Then I need it to assign a four digit number on the end to complete a unique reg number for the cat.
Example:
Breed: Persian 1st part of reg #: PER
Sex: Male 2nd part of reg #: 01
Color: Black 3rd part of reg #: 05
Pattern: Solid 4th part of reg #: SOL
So by user input we have:
PER0105SOL-
Since there can be Many Solid black male persians
each one needs it's own 4 digit unique number attached at the end, such as 2001.
Once that happens the whole number PER0105SOL-2001
will be stored with the cats name and such i another table called simply Cats.
Ideally, the 4 digit number should start with a 2 as they already use a program written about 13 years ago in Dbase that uses a 0 or a 1.
I know it's alot, Im not asking anyone to do it for me, just for some help, if this is even possible..
I appreciate your time!
KT
and for the 4-digit code . . .
hold a table in your database which stores a 4-digit code (the one you'd like to start with, eg 2001). This will be the only entry in the that table. Then read this off to complete your cat number, add 1 to it ready for the next moggy and your application will be purr-fect.
Say the table is CodeDigits and the field is Code. with a value of 2001. Put a command button on your form. In the code module for the form add this code for the click event of the command button:
dim db as database, myCode as string
dim rs as recordset
set db = currentdb
set rs = db.openrecordset("Codedigits",2)
rs.movefirst
myCode = rs!Code ' 4-dig code for this cat
rscode.edit ' now we'll update the code
rs!Code = rsCode +1 ' add 1 to the code
rscode.update ' store the codeready for next cat
now do something like :
CompleteCatCode = left(txtBreed,3) & left(sex,1) etc etc & add MyCode at the end
Now save the CompleteCatCode to your database. no problem
You need a table of individual cats
Ken,
I was thinking about your question a bit more deeply, you might not realise that you need a table of individual cats. In the end, despite being a puss of a colour and a type etc, it has to be an individual cat
I can give you a much better design than codes.
email me, I'll sort it for you, in memoriam of my short-lived ginger visitor of last week.
Peter Hall
Error - user type not defined
KTaylor - Try adding the characters DAO. in front of your database and recordset dim statements:
dim db as DAO.database, myCode as string
dim rs as DAO.recordset
You also may need to add a reference to the DAO objects. Open up a VBA code window, click TOOLS / REFERENCES and look for "Microsoft DAO Object Library". Put a checkmark in it's box and see if that helps.
PETER - Sorry for the loss of your pet. They do become family members don't they.
sequential number problem
Thank you Peter
I too had a need for a similar lookup - my app needed to number reports sequentially - I had a problem using the code but did manage to make it work - here is my version:
Dim db As Database
Set db = CurrentDb
Set rs = db.OpenRecordset("CORnum", 2)
rs.MoveFirst ' go to first record
[COR-ID] = rs![COR-ID] ' 4-dig code for this report
With rs
.Edit ' update the COR-ID
![COR-ID] = rs![COR-ID] + 1 ' add 1 to report #
.Update ' store the result for next report
End With
The table is "CORnum", the field is "COR-ID"
I have several other modules that need sequential numbers - inventory numbers, order numbers, etc. and will use this same method. The method I was using is too complex and might allow the possibilty of duplicates if another user did a similar action.
One question Peter, what is the '2' parameter in the openrecordset line - I couldn't find any documentation on it
Thanks again,
Cyber-guy
1 Attachment(s)
4 digit sequential serial update
Sorry about getting off-track on the original posting about serializing Cats but I think the original question is a basic problem that applies to all sorts of applications, including my own.
Here is a sample db that remembers the last work order number (any number of digits) and updates it by 1 each time a new work order (or cat serial number) is added. Put your starting number in the WorkID field of the NextWorkNum Table. The resulting number can be concatenated with the rest of the cat's identification features to get a unique cat ID.
I'm using this method to generate work order #'s and report #'s in my app. What's nice is that if you cancel out from updating etc., you don't have to reset the number to the last #, it only updates to the next available # after you've done whatever.
Hope this helps