?
Solved

Generate Reference Number on Form submission

Posted on 2009-07-09
5
Medium Priority
?
394 Views
Last Modified: 2012-05-07
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,
0
Comment
Question by:AmitavaCh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 8

Expert Comment

by:stefanx
ID: 24813202
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
 

Author Comment

by:AmitavaCh
ID: 24813317
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
 
LVL 8

Expert Comment

by:stefanx
ID: 24817103
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
 
LVL 8

Accepted Solution

by:
stefanx earned 2000 total points
ID: 24817115
Sorry, the line that says :

Set R = conn.execute(SQL)

should read

Set R = conn.execute(SQL1)

0
 

Author Closing Comment

by:AmitavaCh
ID: 31601568
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

Featured Post

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

764 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