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

How to set a field with a fixed character followed by running increase number

48
I am using Access 2000. I have few tables with primary keys, for example, StaffID, OrgID, CourseID and BookingID. In order for me to recognize my IDs easily later, I want to set a fixed character in front of the auto running number, for example, S for Staff, O for Org, C for course and B for Booking followed by the running increase number everytime I enter a record. How and what should I do to get the result I want?
Sep 14 '07 #1
5 2178
JConsulting
603 Expert 512MB
I am using Access 2000. I have few tables with primary keys, for example, StaffID, OrgID, CourseID and BookingID. In order for me to recognize my IDs easily later, I want to set a fixed character in front of the auto running number, for example, S for Staff, O for Org, C for course and B for Booking followed by the running increase number everytime I enter a record. How and what should I do to get the result I want?

a new text field next to your autonumber field to hold the value gathered from using a function like this one.

Expand|Select|Wrap|Line Numbers
  1. Function UpdateCounter() As String
  2. Dim myVal
  3. myVal = DMax("ID", "tblTest")
  4. UpdateCounter = "Test" & myVal
  5. End Function
  6.  
You can set this function as the default value for this field in any form or query.
another option would be what MS suggests
http://support.microsoft.com/kb/q140908/

J
Sep 14 '07 #2
HowHow
48
Hi J,

Thanks for the code. I had created the function in module as you suggested, however, I do not know how to call the function to my table, forms or queries. I tried the link that you gave but it is not clear enough for me to use the function. Would appreciate if you can show me (or any other link?) how to call the function I created. Thanks again.
Sep 14 '07 #3
JConsulting
603 Expert 512MB
Hi J,

Thanks for the code. I had created the function in module as you suggested, however, I do not know how to call the function to my table, forms or queries. I tried the link that you gave but it is not clear enough for me to use the function. Would appreciate if you can show me (or any other link?) how to call the function I created. Thanks again.

you won't be able to do it directly from the table. you can however use it as the default value on a form. If you have that "extra" field in your table already,

in the default value property you put =Functionname()

If you already have values in the table, and you need to backfill, you need to run an update query where you can update the field to "Text" & [ID] and it will put the value in the older records. The default will then automatically put the new value into the field when you add a new record.
J
Sep 14 '07 #4
HowHow
48
Hi J,

I shall find out more about function and then use it in tables, forms and query. It looks complicated for me as I am not familiar with module.
However,found one easier solution from someone. In table, set data type to AutoNumber, then go to Format property, type \S#. In my case, S stand for StaffID and it will auto increase number with a S in front. I am now trying to find out how to make it two digit, so that it will add S01, S02 instead of S1, S2..etc. Any idea?
Sep 17 '07 #5
HowHow
48
Hi J,

I shall find out more about function and then use it in tables, forms and query. It looks complicated for me as I am not familiar with module.
However,found one easier solution from someone. In table, set data type to AutoNumber, then go to Format property, type \S#. In my case, S stand for StaffID and it will auto increase number with a S in front. I am now trying to find out how to make it two digit, so that it will add S01, S02 instead of S1, S2..etc. Any idea?
Case closed. I was thinking of using single digit and double digit to differentiate the ID, eg CourseID and ContactID, however, now I figure out that I can add more than one character in front of the auto number, eg,
Expand|Select|Wrap|Line Numbers
  1.  \CS#  
and
Expand|Select|Wrap|Line Numbers
  1. \CT#
. Thanks.
Sep 19 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

26
by: Adrian Parker | last post by:
I'm using the code below in my project. When I print all of these fixed length string variables, one per line, they strings in questions do not properly pad with 0s. strQuantity prints as " ...
2
by: Miss Livvy | last post by:
Would it be OK to use varchar(5) instead of char(5) as the first field of a composite clustered index? My gut tells me that varchar would be a bad idea, but I am not finding much information on...
4
by: Colin Graham | last post by:
Hi there, Im very new to javascript and this is my first bit of javascript coding. I have to write a validation check for two fields that they don't contain all the same characters e.g., ...
4
by: Chuck | last post by:
Hello, I have an Access XP database that has several fields. One of the fields is a text field and has an account number that is preceeded by a text character, like: F102354. Every account...
3
by: John young | last post by:
I have been looking for an answer to a problem and have found this group and hope you can assist . I have been re doing a data base I have made for a car club I am with and have been trying to...
3
by: AA Arens | last post by:
When I want the first character of a field to be Uppercased, I need to make an input mask, like >L< followed by ??????? for example. But this mask creates ____ in an unfilled field, which I don't...
2
by: Robert Fitzpatrick | last post by:
I have a field in my pgsql 7.4.2 table that is char(6) type. This holds an ID that contains only numbers, but must be six characters in length. First two chars are the year followed by a sequential...
24
by: garyusenet | last post by:
I'm working on a data file and can't find any common delimmiters in the file to indicate the end of one row of data and the start of the next. Rows are not on individual lines but run accross...
3
by: kvnsmnsn | last post by:
I've written the following Javascript file that includes an input text field and an output text field, the latter of which is initialized to zero. Each time the user enters a number in the input...
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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:
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
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: 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...

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.