This topic is locked

EditOnload: dict or where, I'm confused

2/1/2007 2:42:37 PM
ASPRunnerPro General questions
B
bluecells author

Hi,
I would like to recall 2 fields from the master table and display them on the edit page (to give users a bit of context).

However I could not manage to write a correct string for the recordset.
This is the most advanced version of my code:
Sub EditOnLoad(where)
Session("termino_entry") = ""

Session("domain") = ""
str = "select [termino_entry], [domain] from [1_parents] where [ID]='" & Session(strTableName & "_masterkey1") &"'"
Set rsTemp = server.CreateObject("ADODB.Recordset")

rsTemp.open str, dbConnection
Session("termino_entry") = rsTemp("termino_entry")

Session("domain") = rsTemp("domain")
rsTemp.close : set rsTemp = nothing
End Sub
I would have replaced Session(strTableName & "_masterkey1") by the parent master key stored in the field called "link" on the edit page but dict("link") does not work.

Also, I thought that "select [termino_entry], [domain] from [1_parents] where " & where would have been my solution. but no.
There is something I need to learn apparently. Thanks in advance for your kind assistance.

Sergey Kornilov admin 2/1/2007

Your code looks good. You just need to print values you retrieved from the master table.

Sub EditOnLoad(where)

Session("termino_entry") = ""

Session("domain") = ""
str = "select [termino_entry], [domain] from [1_parents] where [ID]='" & Session(strTableName & "_masterkey1") &"'"
Set rsTemp = server.CreateObject("ADODB.Recordset")

rsTemp.open str, dbConnection
Session("termino_entry") = rsTemp("termino_entry")

Session("domain") = rsTemp("domain")
rsTemp.close : set rsTemp = nothing
Response.write Session("termino_entry") & " " & Session("domain")
End Sub

B
bluecells author 2/1/2007

It looks good to me too <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=15128&image=1&table=forumreplies' class='bbc_emoticon' alt=':rolleyes:' />
But:

Error number -2147217913

Error description [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.

URL /2_children_edit.asp

SQL query select [N°], [language], [entry], [entry_date], [comment], [validation_date_customer], [validation_date_agency], [0K_import], [OK_customer], [comment_import],

[link], [Last_change] From [2_children] where ([2_children].[N°]=1)

Additional info Event: Call EditOnLoad(sWhere)

Sergey Kornilov admin 2/1/2007

That's why posting error message is important - you can get your answer much faster.
What is the data type of N° field?
If this field is a text one you need to add single quotes around key column value.
As a side note - I won't recommend to use special characters in field names especially when it comes to key columns.

B
bluecells author 2/2/2007

Thanks.
[N°] is an Auto Number
But I do not understand why this query is a problem because when I set ID to 1 manually:

str = "select [termino_entry], [domain] from [1_parents] where [ID]=1"
the edit page opens with the right record (but shows master fields [domain] and [termino_entry ] for ID=1 which is not relevant).
Also, the query shown in the error message is the one that creates the edit page but not the one I would like to use to retrieve my master fields.
Why is there conflict between the 2? I am sure I am mixingup something.
Jerome

Sergey Kornilov admin 2/2/2007

Jerome,
I'm confused as well.
Do I understand it correctly that wrong master record is pulled and displayed?
Session(strTableName & "_masterkey1") is populated with correct master key value if you choose master record first and tehn proceed to the details table after that. Is that your scenario?

C
clig 2/2/2007

It looks good to me too <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=15163&image=1&table=forumreplies' class='bbc_emoticon' alt=':rolleyes:' />

But:

Error number -2147217913

Error description [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.

URL /2_children_edit.asp

SQL query select [N°], [language], [entry], [entry_date], [comment], [validation_date_customer], [validation_date_agency], [0K_import], [OK_customer], [comment_import],

[link], [Last_change] From [2_children] where ([2_children].[N°]=1)

Additional info Event: Call EditOnLoad(sWhere)


may have to play with cstr(masterkey) or a & "'" & ....

B
bluecells author 2/2/2007

Thanks for this input but I don't understand it.

What do you mean?
To answer Sergey:
In order to debug and narrow the chance of errors, I have tried

str = "select [termino_entry], [domain] from [1_parents] where [ID]=1"

and it works.
Of course I don't get the parent fields I want but the ones corresponding to ID=1. So far so good.
Now when I try:

str = "select [termino_entry], [domain] from [1_parents] where [ID]='" & Session(strTableName & "_masterkey1") &"'"
I get a SQL error message but not on that very string but on the one that generates the edit page and that generally works.

I can understand that a syntax error in the onload event can hinder the page to load. But then how can I debug?
Thank you for your patience. I think this is a pb of methodology from my side.

In the meantime, I will try to rename my fields to avoid problems with exotic characters.
Have a nice WE

Sergey Kornilov admin 2/2/2007

Things looks better now.
I guess Session(strTableName & "_masterkey1") variable is not populated because you trying to access edit page of details table directly.

To populate this variable you need to choose master record first.
To print SQL query on the page put the following before opening a recordset:
response.write str : response.flush

B
bluecells author 2/8/2007

Thank you for the tip.
But all my problem consists of choosing the master record.

  1. When I am coming from the master table page.

    In that case I should be able to populate Session(strTableName & "_masterkey1") directly, shouldn't I?
  2. When I edit the detail table directly (without going through the parent record)

    This one should be a bit more difficult.
    I just want to retrieve the key of the master record when I am in the Edit page of the detail record.

  • Jerome

Sergey Kornilov admin 2/9/2007

If you proceed to detail table directly run a SQL query that retrieves master key value from the detail record.
After that build another query that retrieves master table record using this master key.