?
Solved

How Can I Add an Automatic Seq # to the Value of Another Text Field?

Posted on 2011-05-11
10
Medium Priority
?
197 Views
Last Modified: 2012-05-11
How Can I Add an Automatic Seq # to the Value of Another Text Field, and Then Set That as The Value of a Different Field?

For example, one of the fileds may be KO-11-01, I would then want to be able to populate a field as KO-11-01-01, the next record as KO-11-01-02, etc...
0
Comment
Question by:Rex85
  • 4
  • 4
  • 2
10 Comments
 
LVL 44

Accepted Solution

by:
GRayL earned 1000 total points
ID: 35742023
To do this you need a primary key for the table.  Assuming the key is named pk, the table as myTable and the fld as fldText

SELECT a.fldText,  a.fldText & "-" & Format((SELECT Count(b.pk) FROM myTable b WHERE b.pk>=a.pk AND b.fldText = a.fldText),"00") AS NoSeq FROM myTable a ORDER BY a.fldText, a.pk

0
 

Author Comment

by:Rex85
ID: 35742045
I'm sorry. I wasn't clear. I am doing this in a form, not a query. It would be some VBA that is triggered I believe,
0
 
LVL 21

Assisted Solution

by:Boyd (HiTechCoach) Trimmell, Microsoft Access MVP
Boyd (HiTechCoach) Trimmell, Microsoft Access MVP earned 1000 total points
ID: 35743234
I recommend storing the seq number in a separate field.

You would calculate the KO-11-01-01 as needed.

To get the next  number you can use the DMax()+1 to the value.

I like to use the Form's On Current event for this:

Example code in a sub form:
Private Sub Form_Current()
                   
  If Me.NewRecord Then
     Dim lngSortOrder As Long

     lngSortOrder = Nz(DMax("[SortOrder]", "[MyTableNme]", "ForeignKeyFile=" & Me.Parent.[PrimaryKeyControl]), 0)

     Me.SortOrder = lngSortOrder + 1
  
  End If

' save the record
If Me.Dirty Then Me.Dirty = False

End Sub

Open in new window


This is from an actual working application. I have change the object names to hopefully make it easier to understand..
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 44

Expert Comment

by:GRayL
ID: 35743269
Whether in code or in a query you still need a primary key in the table.
0
 
LVL 44

Expert Comment

by:GRayL
ID: 35743276
By doing it in a form do you want to 'save 'save' the number in the table or just 'see' it on each new iteration?
0
 

Author Comment

by:Rex85
ID: 35746324
I would definitely want to Save it in the table.
0
 
LVL 21
ID: 35747596
I As previously stated, I would store the sequence number is a separate field.
0
 
LVL 44

Expert Comment

by:GRayL
ID: 35748632
Rex05:  Have you been able to try my solution?  I'm ready to help if you have a problem.
0
 

Author Comment

by:Rex85
ID: 35749565
I am working with all of your comments now. thank you.
0
 

Author Closing Comment

by:Rex85
ID: 35923127
Sorry it took me so long.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question