Solved

Generate Reference Number on Form submission

Posted on 2009-07-09
5
378 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
  • 3
  • 2
5 Comments
 
LVL 8

Expert Comment

by:stefanx
Comment Utility
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
Comment Utility
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
Comment Utility
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 500 total points
Comment Utility
Sorry, the line that says :

Set R = conn.execute(SQL)

should read

Set R = conn.execute(SQL1)

0
 

Author Closing Comment

by:AmitavaCh
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now