Generate Reference Number on Form submission

I have developed a form with few fields in it. The form is working fine now and meets all my requirement, which I planned till date.
Now, I was just thinking to generate 'Reference ID' or 'Request ID' while form submission and display the following message on the page e.g. Thank you for submitting your request. Your reference ID is [Reference ID/Request ID]. Please mention this Reference ID for future correspondce.
Would need your help on how to generate this Unique Reference ID.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I would imagine you save the requests in a database table with an auto-increment id fields?
If so,why not just use the id as the reference number ?
AmitavaChAuthor Commented:
Yes, there is an autonumber field 'RecID' in the table.
There are three other fields such as 'tdate, RecName, email & msg'
Can you help me on this please 'Where & how to write the code'. The code of my submit.asp page is as mentioned below:
Secondly, is there any way I print another sequencial no. e.g. T0001, T0002...and store the same in the same table (in an additional field/column i.e. Reference No.)
***FILE No.1 auto.asp***
function validation(){
	var RecName=document.myform.RecName.value;	
	var msg=document.myform.msg.value;
	alert ("Please mention your name !");
	return false;}
	if(email == ""){
	alert("You have not mentioned your email ID!");;
	return false;}
	if((email.indexOf('@')>0)== false){
		alert("Please mention your email ID");;
		return false;}
	if((email.indexOf('.com')>0)== false){
		alert("Please mention your email ID");;
		return false;}
	alert("Remarks please!");
	return false;}
	return true;
// -->
<H3>Autonumber Example</H3>
<form name="myform" method="post" action="submit.asp" onsubmit="return validation()">
<!--BR><B>RecID: </B><INPUT SIZE=5 MAXLENGTH=5 NAME=RecID tabindex="1"-->
<BR><B>Name: </B><INPUT SIZE=30 MAXLENGTH=50 NAME=RecName tabindex="2">
<BR><B>Email: </B><INPUT SIZE=30 MAXLENGTH=50 NAME=email tabindex="3"><b><br>
Message:</b><font size="1" face="Verdana"><textarea name="msg" cols="25" rows="6" style="background-color: #EAEBB1; color: #800000" tabindex="3"></textarea></font>
<input type="image" border="0" name="imageField" src="Submit.gif" width="100" height="18">
***FILE No.2 submit.asp ***
dim RecID, tdate, RecName, email, msg
RecID=trim(Replace(request.form("RecID"), "'","''"))
RecName=trim(Replace(request.form("RecName"), "'","''"))
email=trim(Replace(request.form("email"), "'","''"))
msg=trim(Replace(request.form("msg"), "'","''"))
	ISDataPath = Server.MapPath("auto.mdb")
	Set conn = Server.CreateObject("adodb.connection")
	conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & ISDataPath 
SQL1 = "Insert into autoTable (tdate,recName,email,msg) values('" &tdate& "','" &RecName& "','" &email& "','" &msg& "')"
		conn.execute (SQL1)
set conn=nothing
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Thank You, for your participation!</title>
<div align="center">
  <table border="0" width="780" height="450">
      <td width="100%">
        <div align="center">
          <table border="0" width="760">
              <td width="760" height="119">&nbsp;</td>
              <td width="760" height="300">
                <p align="center"><font face="Arial" size="2" color="#FFFFFF">
				<p align="center"><font face="Arial" size="2" color="#FFFFFF">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
				Amitava Chatterjee</font></td>
              <td width="760" height="30">
                <p align="right"><font class="label" size="2" face="Arial">
				<a orgurl="javascript:history.go(-1)" href="javascript:history.go(-1)">
				<font color="#FFFFFF">Back</font></a></font></td>

Open in new window
After This:

SQL1 = "Insert into autoTable (tdate,recName,email,msg) values('" &tdate& "','" &RecName& "','" &email& "','" &msg& "')"
conn.execute (SQL1)

'--- Get the ID of the inserted record ---

SQL1 = "SELECT MAX(RecID) FROM autoTable"
Set R = conn.execute(sql)
NewID = R.Fields(0)
Set R = Nothing
'--- You now have the record in NewID ---
'--- Carry on with your code as before ---

In your HTML, now just refer to the ID in a way as below:

  <td width="760" height="300">
  <p align="center"><font face="Arial" size="2" color="#FFFFFF">
  Thanks, you reference ID is T<% = NewID %></font></p>
  <p align="center"><font face="Arial" size="2" color="#FFFFFF">                          
  Amitava Chatterjee</font></td>

Some notes:

This is not the best way. The proper way would actually be to create a recordset, insert the data and then read back the RecID from the
recordset. The MAX(RecID) is just the lazy man's way to do it, and assumes that your Access database assigns ID's sequentially. There is
a slight chance that you get the wrong ID if you have multiple people submitting requests at the same time. For low volume sites, this
is fine though. I am assuming your site is low volume because you are using MS Access rather than SQL Server ;) If you were using SQL Express,
it would be a lot easier because you would the just may SQL1 something like SELECT @@IDENTITY FROM INSERT INTO autoTable(....) ;)

Hope this helps you nevertheless.
Sorry, the line that says :

Set R = conn.execute(SQL)

should read

Set R = conn.execute(SQL1)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AmitavaChAuthor Commented:
Thank you very much for such a detailed explanation and efforts to write the code for me. Yes, this is working and solve my pupose.
I am aware of the limitation of MS Access and still in the begginers's stage in MS SQL. Keen to learn working with SQL and migrate to SQL shortly.
Once again thank you very much.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.