Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Initializing new record for recordset

Status
Not open for further replies.

david7777777777

Programmer
Sep 26, 2001
417
US
I currently have an ASP page that contains recordsets, combo boxes, and some textboxes used to enter a new record into the SQL 2000 database. To add a new record, I'm using the method where you click a button (btnNewEntry) to "initialize" a new blank record in the recordset (rsTapes), then you use the DTC textboxes, combo boxes, an d so on to enter the data for the new record, then you click the Save button (btnSave) to actually save the new record.

Here is the relevent code for these two buttons:

The NEW ENTRY button:
Sub btnNewEntry_onclick()
rsTapes.addRecord

The SAVE button:
Sub btnSave_onclick()
dim fieldsarray(11)
dim valuesarray(11)
fieldsarray(0) = "lstOrigin"
fieldsarray(1) = "lstDestination"
and so on.........
rsTapes.updateRecord fieldsarray, valuesarray

THE PROBLEM:
Currently, I have a hyperlink on a page that brings up the initial [New Entry] button. The user then clicks the [New Entry] button and all of the DTC's become visible so they can enter the data, and then click the [Save] button.

THE PREFERRED SOLUTION
What I'd like to have is this: when they click on that hyperlink (text) on the navigation page, I want that click to also do the job of the [New Entry] button by initializing the new blank record for the recordset (rsTapes). I think the page object has to be involved for this to work but I cannot seem to figure out how to make it work according to the book and help files. Can anyone explain this process to me please? Thanks.





 

Hi,

you can do it without PageObject(I never seem to get it to work properly :-( ). Just send a parameter in your link:

Mypage.asp?rec=new - put whatever makes sense to you and then check the value on server side

Sub thisPage_onenter()
if Request.QueryString("rec")="new" then
btnNewEntry_onclick()
end if
End Sub "Defeat is not the worst of failures. Not to have tried is the true failure."
-George E. Woodberry
 
Ok that worked, but now I have another problem. I had originally been setting my list boxes to display a message to the user when the page initially loaded so the user was presented with a nice, friendly, clean data entry form. Here's the code for that:

Sub thisPage_onenter()
if thispage.firstEntered then
lstOrigin.addItem "Select Origin", "",0
lstDestination.addItem "Select Destination", "",0
txtDateSent.value = ""
lstSentBy.addItem "Sent By...", "",0
txtTrackingNumber.value = ""
txtBackupDate.value = ""
lstServer.addItem "Select Server", "",0
lstWeek.addItem "Select Week", "",0
lstDay.addItem "Select Day", "",0
txtComments.value = ""
End If
End Sub

But now with re-arranging the code to incorporate what you just showed me how to do and load the page from a hyperlink (thanks!), I cannot seem to find the correct event to grab to apply this code. I tried placing this code on the button on_click event but I can't get it to work. I'm not getting any errors, it just doesn't work. It's like this code doesn't even exist on the page. Any ideas how I can fix this? Thanks.
 
Hi,

as I see it you can do 2 things.

1. Add server side code between <head> tags before all your scripts:

<head>
<meta .... other stuff here>

<%if Request.QueryString(&quot;rec&quot;)=&quot;new&quot; then
btnNewEntry_onclick()
end if%>

<script ...>
Sub thisPage_onenter()
if thispage.firstEntered then
lstOrigin.addItem &quot;Select Origin&quot;, &quot;&quot;,0
lstDestination.addItem &quot;Select Destination&quot;, &quot;&quot;,0
... and so on
</script>

2. If all the code you need from btnNewEntry is adding a record, you could just put:

Sub thisPage_onenter()
if thispage.firstEntered then
if Request.QueryString(&quot;rec&quot;)=&quot;new&quot; then
rsTapes.addRecord
end if
lstOrigin.addItem &quot;Select Origin&quot;, &quot;&quot;,0
lstDestination.addItem &quot;Select Destination&quot;, &quot;&quot;,0
txtDateSent.value = &quot;&quot;
lstSentBy.addItem &quot;Sent By...&quot;, &quot;&quot;,0
txtTrackingNumber.value = &quot;&quot;
txtBackupDate.value = &quot;&quot;
lstServer.addItem &quot;Select Server&quot;, &quot;&quot;,0
lstWeek.addItem &quot;Select Week&quot;, &quot;&quot;,0
lstDay.addItem &quot;Select Day&quot;, &quot;&quot;,0
txtComments.value = &quot;&quot;
End If
End Sub

this should do it, but i can't be sure since i don't have all your code. &quot;Defeat is not the worst of failures. Not to have tried is the true failure.&quot;
-George E. Woodberry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top