Connecting Tech Pros Worldwide Forums | Help | Site Map

autonumbering of a field with several categories

Newbie
 
Join Date: May 2009
Posts: 2
#1: May 28 '09
hi guys, im new in microsoft access and i got stuck with some problems.
i created a table called inventory transaction and the fields are 'transaction No (PK)' "transaction reason', 'transaction date','items', etc.
Here's my areas of concern.
1. transaction code consist of several categories such as 'production' and 'purchases', if i select "production" as my transaction reason, transaction No will start with 1. and if i select "purchases", transaction no. should also starts with 1. in short Transaction No sequence should be separate for the 2 categories

tnx a lot

NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,747
#2: May 28 '09

re: autonumbering of a field with several categories


In these circumstances it is not AutoNumbering you need. It's explicit, controlled setting of the number instead.

We can help with this but could you first explain where Transaction Code fits in? You gave a list of fields, then proceeded to explain your problem with reference to a field you hadn't included. This muddies the waters rather and I don't want to proceed with a fuzzy understanding of your problem as that way leads to problems and confusions.

This will work much better if you can post the meta-data (info about the layout / structure) of the table in the same way as I use in my example. Click on the Reply button and you will have access to all the codes I've used. PK & FK stand for Primary Key & Foreign Key respectively. Please don't use any TABs in your formatted layout as this will not display correctly - Spaces only for layout.
Table Name=[tblStudent]
Expand|Select|Wrap|Line Numbers
  1. Field           Type        IndexInfo
  2. StudentID       AutoNumber  PK
  3. Family          String      FK
  4. SName           String
  5. University      String      FK
  6. Mark            Numeric
  7. LastAttendance  Date/Time
Newbie
 
Join Date: May 2009
Posts: 2
#3: May 30 '09

re: autonumbering of a field with several categories


tnx neo, these are some info abt my proj.
Table=[Inventory Transaction]
Expand|Select|Wrap|Line Numbers
  1. Field               Type
  2. Transaction Code    autonumber  PK
  3. Transaction Reason  text
  4. Transaction Date    date
  5. Item Code           text
  6. Transaction Qty     number
I have 2 transaction reasons which are "production" and "puchases". i want each of them to have separate transaction code numbering/sort

tnx
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,747
#4: May 30 '09

re: autonumbering of a field with several categories


So. [Transaction No] doesn't exist at all. Please be more careful in future.

As for your question, the [Transaction Code] field needs to be changed to a Number / Long Integer field and something else added into your PK. A PK MUST be unique. You would probably want to add the [Transaction Reason] into the PK such as :
Expand|Select|Wrap|Line Numbers
  1. Field               Type
  2. Transaction Reason  Text    PK (Composite)
  3. Transaction Code    Number  PK (Composite)
  4. Transaction Date    Date
  5. Item Code           Text
  6. Transaction Qty     Number
The new setting for each record would be determined in the code of your form as (assuming TextBox controls of txtTranCode & txtTranCode) :
Expand|Select|Wrap|Line Numbers
  1. txtTranCode=Nz(DMax("[Transaction Code]", _
  2.                     "[Inventory Transaction]", _
  3.                     "[Transaction Reason]=' & txtTranReason & "'")
I hope this clarifies things a bit for you.
Reply


Similar Microsoft Access / VBA bytes