Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access_asp thread: Adding Records Loop


Message #1 by jmendez@k... on Thu, 21 Feb 2002 18:21:32
I am trying to figure out (if possible) a way to add records to a database 

and then have the form clear and be able to add another record.  Books 

that I have gotten always move to some type of results page.  I want to be 

able to stay in the same page and add records continuously so the end user 

does not have to always click to the add record page.  Also is there a way 

to have the cursor jump to the first field in the form rather than having 

the user click in the field.



Below is my code, I hope someone can help me.



Thank You!







<% Option Explicit %>

<!-- #include virtual="common/adovbs.inc" -->

<html>

<body bgcolor="#ffffff" vlink=black><!-- #include file="header.inc" --><p>



<% 

If Request("ProjNbr")="" Or Request("Description")="" Or _

   Request("ProjectName")="" Or Request("WaterSystem")="" Or _

   Request("Location")="" Or Request("Proj_Mgr")="" Then 

%>

<% ShowHeader "Enter New Project" %>

Please fill in all of these fields below. <br>

When you are finished, click the Submit Record button.<p>





<form method="post" action="addrec.asp">

<table>

<tr><td>Project Number:</td>

<td><input size="50" name="ProjNbr" ></td></tr>



<TR><td valign=top>Project Name:</td>

<td><input size=50 name="ProjectName" ></td></TR>



<TR><td valign=top>Description:</td>

<td><TEXTAREA cols=50 name="Description" rows=6></TEXTAREA></td></TR>



<tr><td>Water System:</td>

<td> <select name="WaterSystem" size="1">

  <option selected value="Lihue">Lihue-Hanamaulu</option>

  <option value="Kapaa">Wailua-Kapaa</option>

  <option value="Koloa">Koloa-Poipu</option>

  <option value="Waimea">Waimea-Kekaha</option>

  <option value="Haena">Haena-Wainiha</option>

</select></td></tr>



<tr><td>Location:</td>

<td><input size="10" name="Location" ></td></tr>



<tr><td>Project Type:</td>

<td><input size="15" name="Proj_Type" ></td></tr>



<tr><td>Project Manager:</td>

<td><input size="50" name="Proj_Mgr" ></td></tr>



<tr><td>Percent Complete:</td>

<td><input size="3" name="Pct_Complete" ></td></tr>



<tr><td>Estimated Cost:</td>

<td><input size="50" name="Est_Cost"></td></tr>



<tr><td><input type="submit" value="Submit Record"></td></tr>

</table>

</form>



<% Else %>

<%

Dim Query, Connect, Classifieds, Place



ShowHeader "Enter New Project"



On Error Resume Next



Set Connect = Server.CreateObject("ADODB.Connection")

Connect.Open "ProjectInfo"



Set Classifieds = Server.CreateObject("ADODB.Recordset")

Classifieds.Open "Proj_Info",Connect,adOpenDynamic,adLockOptimistic,adCmdTa

ble



Classifieds.AddNew

Classifieds("Project_Nbr") = Request("ProjNbr")

Classifieds("Project_Name") = Request("ProjectName")

Classifieds("Description") = Request("Description")

Classifieds("WaterSystem") = Request("WaterSystem")

Classifieds("Location") = Request("Location")

Classifieds("Proj_Type") = Request("Proj_Type")

Classifieds("Proj_Mgr") = Request("Proj_Mgr")

Classifieds("Pct_Complete") = Request("Pct_Complete")

Classifieds("Est_Cost") = Request("Est_Cost")

Classifieds.Update

'Classifieds.Close



If Err.Number = 0 Then %>

<font size=5><i>Record Had Been Added to the Table.</i></font><p>

<A href="placead.asp">Add Another Record</A><p>

<% Else %>

There was an error placing your ad.<p>

Error #<%=Err.Number%>  : <%=Err.Description%><p>

<% End If %>

<% End If %></p>





</body>

</html>
Message #2 by "Caroline & Hossein" <mach3@w...> on Thu, 21 Feb 2002 22:22:41 +0100
Hi

    You need one html/asp (ZZZ.asp) file and another asp file (XXX.asp).

In the first page make your text box and etc. with a form. in the form

action send your data which should be add (insert) into your table: action 

XXX.asp in the end of your code in this page you add response.redirect

"ZZZ.asp". so the data will be send and you see a clear page again. if you

use frame then add:



Response.write " <base target = dynamic>"

Response.redirect "ba.asp"



regards

Hossein









----- Original Message -----

From: <jmendez@k...>

To: "Access ASP" <access_asp@p...>

Sent: Thursday, February 21, 2002 6:21 PM

Subject: [access_asp] Adding Records Loop





> I am trying to figure out (if possible) a way to add records to a database

> and then have the form clear and be able to add another record.  Books

> that I have gotten always move to some type of results page.  I want to be

> able to stay in the same page and add records continuously so the end user

> does not have to always click to the add record page.  Also is there a way

> to have the cursor jump to the first field in the form rather than having

> the user click in the field.

>

> Below is my code, I hope someone can help me.

>

> Thank You!

>

>

>

> <% Option Explicit %>

> <!-- #include virtual="common/adovbs.inc" -->

> <html>

> <body bgcolor="#ffffff" vlink=black><!-- #include file="header.inc" --><p>

>

> <%

> If Request("ProjNbr")="" Or Request("Description")="" Or _

>    Request("ProjectName")="" Or Request("WaterSystem")="" Or _

>    Request("Location")="" Or Request("Proj_Mgr")="" Then

> %>

> <% ShowHeader "Enter New Project" %>

> Please fill in all of these fields below. <br>

> When you are finished, click the Submit Record button.<p>

>

>

> <form method="post" action="addrec.asp">

> <table>

> <tr><td>Project Number:</td>

> <td><input size="50" name="ProjNbr" ></td></tr>

>

> <TR><td valign=top>Project Name:</td>

> <td><input size=50 name="ProjectName" ></td></TR>

>

> <TR><td valign=top>Description:</td>

> <td><TEXTAREA cols=50 name="Description" rows=6></TEXTAREA></td></TR>

>

> <tr><td>Water System:</td>

> <td> <select name="WaterSystem" size="1">

>   <option selected value="Lihue">Lihue-Hanamaulu</option>

>   <option value="Kapaa">Wailua-Kapaa</option>

>   <option value="Koloa">Koloa-Poipu</option>

>   <option value="Waimea">Waimea-Kekaha</option>

>   <option value="Haena">Haena-Wainiha</option>

> </select></td></tr>

>

> <tr><td>Location:</td>

> <td><input size="10" name="Location" ></td></tr>

>

> <tr><td>Project Type:</td>

> <td><input size="15" name="Proj_Type" ></td></tr>

>

> <tr><td>Project Manager:</td>

> <td><input size="50" name="Proj_Mgr" ></td></tr>

>

> <tr><td>Percent Complete:</td>

> <td><input size="3" name="Pct_Complete" ></td></tr>

>

> <tr><td>Estimated Cost:</td>

> <td><input size="50" name="Est_Cost"></td></tr>

>

> <tr><td><input type="submit" value="Submit Record"></td></tr>

> </table>

> </form>

>

> <% Else %>

> <%

> Dim Query, Connect, Classifieds, Place

>

> ShowHeader "Enter New Project"

>

> On Error Resume Next

>

> Set Connect = Server.CreateObject("ADODB.Connection")

> Connect.Open "ProjectInfo"

>

> Set Classifieds = Server.CreateObject("ADODB.Recordset")

> Classifieds.Open

"Proj_Info",Connect,adOpenDynamic,adLockOptimistic,adCmdTa

> ble

>

> Classifieds.AddNew

> Classifieds("Project_Nbr") = Request("ProjNbr")

> Classifieds("Project_Name") = Request("ProjectName")

> Classifieds("Description") = Request("Description")

> Classifieds("WaterSystem") = Request("WaterSystem")

> Classifieds("Location") = Request("Location")

> Classifieds("Proj_Type") = Request("Proj_Type")

> Classifieds("Proj_Mgr") = Request("Proj_Mgr")

> Classifieds("Pct_Complete") = Request("Pct_Complete")

> Classifieds("Est_Cost") = Request("Est_Cost")

> Classifieds.Update

> 'Classifieds.Close

>

> If Err.Number = 0 Then %>

> <font size=5><i>Record Had Been Added to the Table.</i></font><p>

> <A href="placead.asp">Add Another Record</A><p>

> <% Else %>

> There was an error placing your ad.<p>

> Error #<%=Err.Number%>  : <%=Err.Description%><p>

> <% End If %>

> <% End If %></p>

>

>

> </body>

> </html>




$subst('Email.Unsub').

>



Message #3 by "Ken Schaefer" <ken@a...> on Fri, 22 Feb 2002 10:10:23 +1100
You can post the form to itself.

Then just check if the form was posted to see if you should add something to

the database:



--- page1.asp ---



<%

If Request.Form("postback") = "yes" then



    ' add record to database



End If

%>



<html>

    <body>

        <form method="post">

            <input type="hidden" name="postback" value="yes"

        </form>

    </body>

<html>



To move the cursor to a particular textbox is a client-side javascript

issue. Use the Body's onLoad event handler to do this. Try seeking help at

one of Wrox's Javascript lists: p2p.wrox.com/javascript



Cheers

Ken





~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

From: <jmendez@k...>

Subject: [access_asp] Adding Records Loop





: I am trying to figure out (if possible) a way to add records to a database

: and then have the form clear and be able to add another record.  Books

: that I have gotten always move to some type of results page.  I want to be

: able to stay in the same page and add records continuously so the end user

: does not have to always click to the add record page.  Also is there a way

: to have the cursor jump to the first field in the form rather than having

: the user click in the field.

:

: Below is my code, I hope someone can help me.

:

: Thank You!



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Message #4 by "Raymond Dalton" <rdalton@c...> on Fri, 22 Feb 2002 17:19:26
The way suggested about making the form self submitting and checking for 

submission works well.  I use it for the type of forms that you suggest 

all the time.  For the focus do as he said and use an onload event.  The 

method is



fieldname.focus()



For example using your code:



<body bgcolor="#ffffff" vlink=black onload="javascript:document.forms

[0].ProjNbr.focus();"> 





If you use the name attribute in your form tag you don't have to use the 

forms[0].



For example using your code:



<body bgcolor="#ffffff" vlink=black 

onload="javascript:document.sampleform.ProjNbr.focus();"> 



<form method="post" action="addrec.asp" name="sampleform">



Thanks,



Raymond





> I am trying to figure out (if possible) a way to add records to a 

database 

> and then have the form clear and be able to add another record.  Books 

> that I have gotten always move to some type of results page.  I want to 

be 

> able to stay in the same page and add records continuously so the end 

user 

> does not have to always click to the add record page.  Also is there a 

way 

> to have the cursor jump to the first field in the form rather than 

having 

> the user click in the field.

> 

> Below is my code, I hope someone can help me.

> 

> Thank You!

> 

> 

> 

> <% Option Explicit %>

> <!-- #include virtual="common/adovbs.inc" -->

> <html>

> <body bgcolor="#ffffff" vlink=black><!-- #include file="header.inc" --

><p>

> 

> <% 

> If Request("ProjNbr")="" Or Request("Description")="" Or _

>    Request("ProjectName")="" Or Request("WaterSystem")="" Or _

>    Request("Location")="" Or Request("Proj_Mgr")="" Then 

> %>

> <% ShowHeader "Enter New Project" %>

> Please fill in all of these fields below. <br>

> When you are finished, click the Submit Record button.<p>

> 

> 

> <form method="post" action="addrec.asp">

> <table>

> <tr><td>Project Number:</td>

> <td><input size="50" name="ProjNbr" ></td></tr>

> 

> <TR><td valign=top>Project Name:</td>

> <td><input size=50 name="ProjectName" ></td></TR>

> 

> <TR><td valign=top>Description:</td>

> <td><TEXTAREA cols=50 name="Description" rows=6></TEXTAREA></td></TR>

> 

> <tr><td>Water System:</td>

> <td> <select name="WaterSystem" size="1">

>   <option selected value="Lihue">Lihue-Hanamaulu</option>

>   <option value="Kapaa">Wailua-Kapaa</option>

>   <option value="Koloa">Koloa-Poipu</option>

>   <option value="Waimea">Waimea-Kekaha</option>

>   <option value="Haena">Haena-Wainiha</option>

> </select></td></tr>

> 

> <tr><td>Location:</td>

> <td><input size="10" name="Location" ></td></tr>

> 

> <tr><td>Project Type:</td>

> <td><input size="15" name="Proj_Type" ></td></tr>

> 

> <tr><td>Project Manager:</td>

> <td><input size="50" name="Proj_Mgr" ></td></tr>

> 

> <tr><td>Percent Complete:</td>

> <td><input size="3" name="Pct_Complete" ></td></tr>

> 

> <tr><td>Estimated Cost:</td>

> <td><input size="50" name="Est_Cost"></td></tr>

> 

> <tr><td><input type="submit" value="Submit Record"></td></tr>

> </table>

> </form>

> 

> <% Else %>

> <%

> Dim Query, Connect, Classifieds, Place

> 

> ShowHeader "Enter New Project"

> 

> On Error Resume Next

> 

> Set Connect = Server.CreateObject("ADODB.Connection")

> Connect.Open "ProjectInfo"

> 

> Set Classifieds = Server.CreateObject("ADODB.Recordset")

> 

Classifieds.Open "Proj_Info",Connect,adOpenDynamic,adLockOptimistic,adCmdTa

> ble

> 

> Classifieds.AddNew

> Classifieds("Project_Nbr") = Request("ProjNbr")

> Classifieds("Project_Name") = Request("ProjectName")

> Classifieds("Description") = Request("Description")

> Classifieds("WaterSystem") = Request("WaterSystem")

> Classifieds("Location") = Request("Location")

> Classifieds("Proj_Type") = Request("Proj_Type")

> Classifieds("Proj_Mgr") = Request("Proj_Mgr")

> Classifieds("Pct_Complete") = Request("Pct_Complete")

> Classifieds("Est_Cost") = Request("Est_Cost")

> Classifieds.Update

> 'Classifieds.Close

> 

> If Err.Number = 0 Then %>

> <font size=5><i>Record Had Been Added to the Table.</i></font><p>

> <A href="placead.asp">Add Another Record</A><p>

> <% Else %>

> There was an error placing your ad.<p>

> Error #<%=Err.Number%>  : <%=Err.Description%><p>

> <% End If %>

> <% End If %></p>

> 

> 

> </body>

> </html>
Message #5 by "Mendez, Jeff" <JMendez@k...> on Sun, 24 Feb 2002 17:55:49 -1000
Raymond,

I wanted to thank you very much for answering my distress call.  I am new to

windows programming and ASP and probably have a long ways to get to your

level.



The example that you provided below works well on initial call up of page.

I added the following below as you suggested and it did work perfectly:

<body bgcolor="#ffffff" vlink=black

onload="javascript:document.Addform.ProjNbr.focus();"> 



<form method="post" action="addrec.asp" name="Addform">



However, when my page refreshed, it gave an error message "Error:

'document.Addform.ProjNbr' is not an object.



From there its stops processing.  To refresh my page, which may be the

problem, I added the following which another Person was nice enough to

submit to me:



<META HTTP-EQUIV="Refresh" Content="1; url="Addrec.asp">



The refresh works very well on its own, but it may be clashing with the line

of code you helped me out with.



Any ideas you could give me would be greatly appreciated.



Jeff





-----Original Message-----

From: Raymond Dalton [mailto:rdalton@c...]

Sent: Friday, February 22, 2002 7:19 AM

To: Access ASP

Subject: [access_asp] Re: Adding Records Loop





The way suggested about making the form self submitting and checking for 

submission works well.  I use it for the type of forms that you suggest 

all the time.  For the focus do as he said and use an onload event.  The 

method is



fieldname.focus()



For example using your code:



<body bgcolor="#ffffff" vlink=black onload="javascript:document.forms

[0].ProjNbr.focus();"> 





If you use the name attribute in your form tag you don't have to use the 

forms[0].



For example using your code:



<body bgcolor="#ffffff" vlink=black 

onload="javascript:document.sampleform.ProjNbr.focus();"> 



<form method="post" action="addrec.asp" name="sampleform">



Thanks,



Raymond





> I am trying to figure out (if possible) a way to add records to a 

database 

> and then have the form clear and be able to add another record.  Books 

> that I have gotten always move to some type of results page.  I want to 

be 

> able to stay in the same page and add records continuously so the end 

user 

> does not have to always click to the add record page.  Also is there a 

way 

> to have the cursor jump to the first field in the form rather than 

having 

> the user click in the field.

> 

> Below is my code, I hope someone can help me.

> 

> Thank You!

> 

> 

> 

> <% Option Explicit %>

> <!-- #include virtual="common/adovbs.inc" -->

> <html>

> <body bgcolor="#ffffff" vlink=black><!-- #include file="header.inc" --

><p>

> 

> <% 

> If Request("ProjNbr")="" Or Request("Description")="" Or _

>    Request("ProjectName")="" Or Request("WaterSystem")="" Or _

>    Request("Location")="" Or Request("Proj_Mgr")="" Then 

> %>

> <% ShowHeader "Enter New Project" %>

> Please fill in all of these fields below. <br>

> When you are finished, click the Submit Record button.<p>

> 

> 

> <form method="post" action="addrec.asp">

> <table>

> <tr><td>Project Number:</td>

> <td><input size="50" name="ProjNbr" ></td></tr>

> 

> <TR><td valign=top>Project Name:</td>

> <td><input size=50 name="ProjectName" ></td></TR>

> 

> <TR><td valign=top>Description:</td>

> <td><TEXTAREA cols=50 name="Description" rows=6></TEXTAREA></td></TR>

> 

> <tr><td>Water System:</td>

> <td> <select name="WaterSystem" size="1">

>   <option selected value="Lihue">Lihue-Hanamaulu</option>

>   <option value="Kapaa">Wailua-Kapaa</option>

>   <option value="Koloa">Koloa-Poipu</option>

>   <option value="Waimea">Waimea-Kekaha</option>

>   <option value="Haena">Haena-Wainiha</option>

> </select></td></tr>

> 

> <tr><td>Location:</td>

> <td><input size="10" name="Location" ></td></tr>

> 

> <tr><td>Project Type:</td>

> <td><input size="15" name="Proj_Type" ></td></tr>

> 

> <tr><td>Project Manager:</td>

> <td><input size="50" name="Proj_Mgr" ></td></tr>

> 

> <tr><td>Percent Complete:</td>

> <td><input size="3" name="Pct_Complete" ></td></tr>

> 

> <tr><td>Estimated Cost:</td>

> <td><input size="50" name="Est_Cost"></td></tr>

> 

> <tr><td><input type="submit" value="Submit Record"></td></tr>

> </table>

> </form>

> 

> <% Else %>

> <%

> Dim Query, Connect, Classifieds, Place

> 

> ShowHeader "Enter New Project"

> 

> On Error Resume Next

> 

> Set Connect = Server.CreateObject("ADODB.Connection")

> Connect.Open "ProjectInfo"

> 

> Set Classifieds = Server.CreateObject("ADODB.Recordset")

> 

Classifieds.Open "Proj_Info",Connect,adOpenDynamic,adLockOptimistic,adCmdTa

> ble

> 

> Classifieds.AddNew

> Classifieds("Project_Nbr") = Request("ProjNbr")

> Classifieds("Project_Name") = Request("ProjectName")

> Classifieds("Description") = Request("Description")

> Classifieds("WaterSystem") = Request("WaterSystem")

> Classifieds("Location") = Request("Location")

> Classifieds("Proj_Type") = Request("Proj_Type")

> Classifieds("Proj_Mgr") = Request("Proj_Mgr")

> Classifieds("Pct_Complete") = Request("Pct_Complete")

> Classifieds("Est_Cost") = Request("Est_Cost")

> Classifieds.Update

> 'Classifieds.Close

> 

> If Err.Number = 0 Then %>

> <font size=5><i>Record Had Been Added to the Table.</i></font><p>

> <A href="placead.asp">Add Another Record</A><p>

> <% Else %>

> There was an error placing your ad.<p>

> Error #<%=Err.Number%>  : <%=Err.Description%><p>

> <% End If %>

> <% End If %></p>

> 

> 

> </body>

> </html>




Message #6 by "Raymond Dalton" <rdalton@c...> on Tue, 26 Feb 2002 01:06:00
Jeff,



We might need to account for the appropriate DOM depending upon what 

browser you are using.  I tested using N4.78 and IE 6, which will usually 

cover any basic issues.



The big thing to check is your capitalization.  Javascript is case 

sensitive.  Make sure that all your references use the same case.  If you 

reference 



onload="javascript:document.Addform.ProjNbr.focus();" 



and the form is actually called addform or the field is actually called 

projnbr then you will get the object not found error, because addform is a 

different name than Addform.



Check this first.  If that isn't the problem then send me your new updated 

page code, and I will look to see what the problem is.



Thanks,



Raymond

  Return to Index