We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


Generate Reference Number on Form submission

AmitavaCh asked
Medium Priority
Last Modified: 2012-05-07
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.

Watch Question

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 ?


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 email=document.myform.email.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.
Unlock this solution and get a sample of our free trial.
(No credit card required)


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
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.