Generate Reference Number on Form submission

Hi!
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.

Regards,
AmitavaChAsked:
Who is Participating?
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.

stefanxCommented:
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 ?
0
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***
<HTML>
<head>
<script>
<!--
function validation(){
 
	var RecName=document.myform.RecName.value;	
	var email=document.myform.email.value;
	var msg=document.myform.msg.value;
 
	if(RecName==""){
	alert ("Please mention your name !");
	document.myform.RecName.focus();
	return false;}
 
	if(email == ""){
	alert("You have not mentioned your email ID!");
	document.myform.email.focus();
	return false;}
	if((email.indexOf('@')>0)== false){
		alert("Please mention your email ID");
		document.myform.email.focus();
		return false;}
	if((email.indexOf('.com')>0)== false){
		alert("Please mention your email ID");
		document.myform.email.focus();
		return false;}
 
	if(msg==""){
	alert("Remarks please!");
	document.myform.msg.focus();
	return false;}
 
	return true;
}
// -->
</script>
</head>
<BODY BGCOLOR=FFFFFF>
<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>
<p>
<BR><BR>
<input type="image" border="0" name="imageField" src="Submit.gif" width="100" height="18">
</p>
</FORM>
</BODY>
</HTML>
 
***FILE No.2 submit.asp ***
<%
dim RecID, tdate, RecName, email, msg
 
tdate=date()
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)
 
 
conn.close
set conn=nothing
 
%>
<html>
<head>
<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>
</head>
<BODY bgcolor="#006699" MARGINHEIGHT="0" TOPMARGIN="0" RIGHTMARGIN="0" LEFTMARGIN="0" BOTTOMMARGIN="0" MARGINWIDTH="0">
<div align="center">
  <center>
  <table border="0" width="780" height="450">
    <tr>
      <td width="100%">
        <div align="center">
          <center>
          <table border="0" width="760">
            <tr>
              <td width="760" height="119">&nbsp;</td>
            </tr>
            <tr>
              <td width="760" height="300">
                <p align="center"><font face="Arial" size="2" color="#FFFFFF">
				Thanks</font></p>
				<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>
            </tr>
          </center>
  </center>
            <tr>
              <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>
            </tr>
          </table>
        </div>
      </td>
    </tr>
  </table>
</div>
 
</body> 

Open in new window

Auto.zip
0
stefanxCommented:
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)
R.Close
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:

<tr>
  <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>
</tr>

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.
0
stefanxCommented:
Sorry, the line that says :

Set R = conn.execute(SQL)

should read

Set R = conn.execute(SQL1)

0

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.
Regards, amitava07@gmail.com
0
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
Databases

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.