CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> ASP

 Primary key transfer between two forms...new!

Print topic Send  topic

Author Message
steve514

Posts: 14
Posted: 07/17/2006, 4:12 PM

Hi,

I am making a web application, and part of it consist of a multi-page form that the user fills out to place an order. I have a database that automatically assigns the record a "Order ID #" once it is added to the database and this ID is the unique primary ID used in linking all my other tables together.

The problem is that I need a way to link the two pages of my form so that, when a user inserts the form on the first page, I can transfer over the primary ID from that order to the next page to pull up the record so that they can continue filling out the same record and not a new one.

I have looked at the CCS TUTORIAL on Multi-page Registration forms. I understand it up until the point where it says to code the needed code in the "after insert event". I have been trying for weeks to figure this problem out. I have searched the forums for days and read all the different codes and ways people suggest to do this and I can't get it to work.

I just need someone to tell me in simple steps with the code included what goes where and on what page so that I can find the last entered primary key and transfer it successfully to the next page loading that record to update.

This is for a big project and any help would be geatly appreciated. Thank you in advance.

I'm using ASP 3.0 w/ Microsoft Access (SQL) database.
View profile  Send private message
peterr


Posts: 5971
Posted: 07/17/2006, 6:10 PM

Please let us know which part of the instructions didn't work for you, and what is the exact problem.
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
DonB
Posted: 07/18/2006, 4:53 AM

Did you use the Microsoft Jet 4.0 OLEDB Provider? I find that I have
problems using Access with other alternatives (e.g., the generic ODBC
driver)

I enter something like this in the 'Use Connection String' field (next to
the 'Build' button in the Connection dialog box):

Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\path\to\database\filename.mdb;Persist Security Info=False

and then querying for

"SELECT @@identity"

gives me the correct value for the last INSERT's autonumber id. Other ODBC
drivers always failed to return a value for me when I used them.

--
DonB

http://www.gotodon.com/ccbth
steve514

Posts: 14
Posted: 07/18/2006, 5:11 AM

Hi,

Thank you for replying to my message. To answer your question peter, the part I was refering to in the Multi-page registration example was step 7 of page 2 which said "Add the appropriate programming code in the Record form's After Insert event as shown in the example". I really need to know exactly what code to put in there on each page to transfer the primary key.

DonB, I'm not quite sure what and where the query string should be for SELECT @@@IDENTITY. I tried putting in the connection string and then a query string for "SELECT @@identity" in the WHERE of my query builder with my primary key equal to it. I have figured out that using this to return the last autogenerated primary key in my database is important, but I still don't know what the code should be and where it should go to transfer this primary key between pages to remain editing the same record.

Please help as I am still loss.....???

Thanks,
Steve
View profile  Send private message
DonB
Posted: 07/18/2006, 11:34 AM

You would do the query in the After Execute Insert event. The form will
have a connection (assume you named it "Connection1" for this duscussion).
So, you can query the SAME (that's important!) connection for @@IDENTITY and
it will return the id of the last row that the connection inserted:

Dim rs, intID

set rs = DBConnection1.Connection.Execute("SELECT @@identity") ' Connection
names get prefixed with "DB"

ID = rs.fields(0) ' The PK of the new row that was just entered

Set rs = nothing

Probably could do a CCDLookUp, but I'm not sure what the 2nd parameter
(table name) would need to be for it to work - maybe just left blank?

--
DonB

http://www.gotodon.com/ccbth
steve514

Posts: 14
Posted: 07/18/2006, 3:17 PM

Hi,

Thank you for your reply. I understand what you are saying above. My only question is once I get the primary key into a variable like that, how do I transfer to the next page so that page 2 loads the same record I just entered only with adding additional information. Keep in mind I am new and the code and simple approach is much appreciated. Please let me know??

Thank you.
View profile  Send private message
DonB
Posted: 07/18/2006, 3:58 PM

The Redirect variable holds the location of the 'next' page. Set it to a
proper URL, including the parameter you wich to pass along. Redirect is
overruled by the form properties, so if you put a "Return Page" property on
a form, or a button in a form, the code you write won't be obeyed.

Set Redirect like this:

Redirect = "nextpage.php?param=" & somevalue.

--
DonB

http://www.gotodon.com/ccbth
steve514

Posts: 14
Posted: 07/18/2006, 4:10 PM

Hi,

I put a "after insert" event into the first page of the form with the following custom code:

Function MPW_Query_AfterInsert(Sender) 'MPW_Query_AfterInsert @2-F1A434D2

'Custom Code @207-73254650
' -------------------------
Dim LastID
LastID = CCDLookup("max([OrderID #])","masterTABLE","", DBdsfdatabase)
Response.Redirect "mpw_form12.asp?OrderID_#=" & LastID
' -------------------------
'End Custom Code

End Function 'Close MPW_Query_AfterInsert @2-54C34B28

I successfully pull the last entered primary key value and send it through the URL to the next page. The problem is that it still doesn't load the record based off of this primary key that was passed through the URL. I was thinking that I might need some sort of code in a before show event on the second page to read in the value to load the already made record to edit it. Please help me with the code in order to load the second page properly now that I can pass the value through the URL...???

Thanks again for everything so far....please keep the feedback coming because I have tried for so long to solve this problem.
View profile  Send private message
steve514

Posts: 14
Posted: 07/19/2006, 7:36 AM

Hey Guys,

I still really need help with this one...please.?

Thank you.
View profile  Send private message
peterr


Posts: 5971
Posted: 07/19/2006, 11:41 AM

Hi Steve,

The example at http://examples.codecharge.com/ExamplePack/MultiStepReg...gistration1.php is included with CodeCharge Studio specifically to answer such questions. There are many other examples provided in CCS and I recommend learning how to use them, otherwise we would have to repeat on the forums everything that is already in the examples...
All necessary code is also included in the examples and you can see it by clicking "Code" tab in CodeCharge Studio. Though you don't need custom code to handle your last question.

Here are instructions on using the examples:
http://docs.codecharge.com/studio3/html/ProgrammingTech...xamplePack.html

_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
wkempees


Posts: 1679
Posted: 07/19/2006, 11:52 AM

If you sucessfully pull the last inserted ID;
and you put it on the URL
and you do get to the requestedpage
and the URL is as you expected
BUT the record form is not in editmode with the required record displayed
THEN
the parameter on the url does not correspond to the parameter the form is expecting.

For instance
........\MyPage?id=1234
if MyPage is correct and displaying, and the 1234 is your last inserted ID but the page is not displaying the data from that inserted record than MPage is expecting another parameter name, as that other parameter is not there, the form goes into INSERT mode.

Walter


_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)

if you liked this info PAYPAL me: http://donate.consultair.eu
View profile  Send private message
steve514

Posts: 14
Posted: 07/19/2006, 12:01 PM

Hi wkempees,

I completely understand what you just said. That is the problem I am having.

On the first page I put the following code into a "after insert" event:

Dim LastID
LastID = CCDLookup("max([OrderID #])","masterTABLE","", DBdsfdatabase)
Redirect = "mpw_form12.asp?OrderID_#=" & LastID

When I click next, it redirects me to the next page with the following url:

http://localhost/DSFapp/MPW_form12.asp?OrderID_#=12

The orderid_# is alwayrs right to as the last entered one.

My problem is that the primary key in my database is called "OrderID #" and the variable I am passing through is OrderID_# since url names can't have spaces in it. I need the specific orderid to be pulled for updating and only that record when I click next on the first record form page. I have read EVERYTHING (every forum post, examples, and CCS tutorials) for the past 4 days now and I can't figure this last bit out. .Please some one (anyone)...help me??

Thank you in advance to whoever can solve this problem. :)
View profile  Send private message
wkempees


Posts: 1679
Posted: 07/19/2006, 12:17 PM

Your primary key is OrderID # ??????
Do you mean that is the name of the key? or of the field?
in both cases it is terribly wrong choosen.
NEVER use special characters in an SQL field name.
Correct that first, work through your code to change all references to that # field and go from there.

If you really do not want to follow that advise it will bring you lots of trouble.
You will then have to CCGetFromGet() this OrderID_# and manually feed it to your Record Form, in the before show, get the value, get the record and go from there.

Please correct the field name!

Walter





_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)

if you liked this info PAYPAL me: http://donate.consultair.eu
View profile  Send private message
steve514

Posts: 14
Posted: 07/19/2006, 12:35 PM

Hi,

I understand what you are saying. I just want to see if I can get this working for now as is. In the "before show" event, do you have any idea what code (after I get in the OrderID_# from the url)I would want to use to manually load the record to edit which is what I have been trying to do for so long???

Thank you. :)
View profile  Send private message
wkempees


Posts: 1679
Posted: 07/19/2006, 12:46 PM

that is a hard one, I will have to check if something can be done in the OnInitialize or BeforeShow.
I am going out now first, after that I will investigate.
(22:15 GMT +1)

_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)

if you liked this info PAYPAL me: http://donate.consultair.eu
View profile  Send private message
peterr


Posts: 5971
Posted: 07/19/2006, 12:59 PM

You shouldn't use any events. You would only need to configure the WHERE section of your record's Data Source to retrieve only the record matching the OrderID. This is same as shown in that example ("users" form on the "MultiStepRegistration2" page).
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
wkempees


Posts: 1679
Posted: 07/19/2006, 1:49 PM

To be exact, and this is tested in CCS# last, Peterr please correct me if I am wrong:

Open the recordfrom in designer
DataSource, press the elipses
change the Where parameter to
leftside : OderID #, integer
condition: equals
rightside: OrderID# type URL

In the redirect change OrderID_# into OrderID#

I have been testing this for you and Peterr is right, after a few seconds I realized it is all in the RecordForm's SQL.
BUT, I was using a normal id field,
this is acceptable:
?id=753
?id#=753
This however is not accepted
?id_#=753

So it is really simple to make it work, if you read the post the answer is there.
Peterr could you check why the _# is not accepted.
I tested by setting the default value in RecordForm VQB to 752
all correct combinations pulled 753 for edit, the _# consistently pulled 752


WAlter


_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)

if you liked this info PAYPAL me: http://donate.consultair.eu
View profile  Send private message
peterr


Posts: 5971
Posted: 07/19/2006, 2:55 PM

OK, I'll check into the "id_#=" issue. Thanks.
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
DonB
Posted: 07/19/2006, 6:39 PM

Not "After Insert", "After Execute Insert". I believe the connection is
closed by the time the first one fires, which means the last insert id is
discarded.

--
DonB

http://www.gotodon.com/ccbth
peterr


Posts: 5971
Posted: 07/20/2006, 2:08 AM

Walter,
Looks like the # character is used in URLs only as an HTML anchor, so it cannot be used in parameters.
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
WKempees
Posted: 07/20/2006, 3:28 AM

Peterr,

Thanks, funny though that the one is and the other is not working id#, id_#.


Steve,
Another pressing reason NOT to use special characters in SQL Table field
definitions.
The space in OrderID # especially bothered me.
Now you see that the hash # also causes unexpected unforseen problems.
Please take this advice and do not use special characters in SQL Table field
definition, the only exception being an
underscore _ between literals like: Order_ID.

Forunately CCS saved your day.

Walter

steve514

Posts: 14
Posted: 07/20/2006, 5:12 AM

Hi,

Thank you so much for helping me with this problem. I took your advice Wkempees and spent the night redesigning the names of my database fixing the primary key name and everything in the asp forms. After I changed the name and got rid of the # number and the _ use, everything worked with what you said above. I finally got it working thank to you guys. I really appreciate this as I seriously spent like days straight trying to figure it out before I posted here.

Thanks again!!!
View profile  Send private message
WKempees
Posted: 07/20/2006, 5:17 AM

Good Job Steve.
Wise decision, time spent now is time saved in the future.

Walter


Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.