XGIS
asked on
VBA Code to transfer ParentID when New record Inserted into Hierarchical Lookup Table
I am trying to transfer a ParentID value to the DMP_Lookup table in my sample ASP database application. The "Town" lookup values are stored in a self-referencing hierarchy table. They are provided to the application using a query "qryTown".
The application gives you the option to "Add" new values while editing a data table form. When I add a new town name (ie Lookup), it does NOT transfer the ParentID that is present in the query. In this case the ParentID = 1, but could be any integer.
The form generator application I am using is AspMaker 10.1. The project is in the attached file (no its not because EE is munted). The program is 17mb and is free to demo. The AspMaker project file is "LookupHierarchyTest.agp". This project is setup with the folder and database path on the root of the c drive.
The support staff sent me the following code to include on the "Row_Inserting" server event. It works if you place in the Parent ID value in, but I want that to be parsed without the need for user intervention. The user ONLY needs to add the Lookup name.
I would have added the project as a zip or rar but this site is so backwards you cant use file types (eg rar, js, agp etc etc) that would actually be used in a professional programming support website. It would be too bad if I needed help with a javascript file. maybe the site should be "Almost EE"....
LookupHierarchy.mdb
AddLookupSample1.gif
AddLookupSample2.gif
The application gives you the option to "Add" new values while editing a data table form. When I add a new town name (ie Lookup), it does NOT transfer the ParentID that is present in the query. In this case the ParentID = 1, but could be any integer.
The form generator application I am using is AspMaker 10.1. The project is in the attached file (no its not because EE is munted). The program is 17mb and is free to demo. The AspMaker project file is "LookupHierarchyTest.agp".
The support staff sent me the following code to include on the "Row_Inserting" server event. It works if you place in the Parent ID value in, but I want that to be parsed without the need for user intervention. The user ONLY needs to add the Lookup name.
Dim ar, ParentName, ParentID
ar = Split(rsnew("Name"), " ") ' Split the name to get table name
ParentName = ar(0)
If ParentName <> rsnew("Name") Then
ParentID = ew_ExecuteScalar("SELECT ID FROM <Table> WHERE Name = '" & ew_AdjustSql(ParentName) & "'")
Else
ParentID = 0
End If
rsnew("ParentID") = ParentID
I would have added the project as a zip or rar but this site is so backwards you cant use file types (eg rar, js, agp etc etc) that would actually be used in a professional programming support website. It would be too bad if I needed help with a javascript file. maybe the site should be "Almost EE"....
LookupHierarchy.mdb
AddLookupSample1.gif
AddLookupSample2.gif
ASKER
the sql needs to do this
NewRecord.gif
NewRecord.gif
There are multiple ways to do this. The way I am showing you is the easiest to show but not really the most efficient. If your database is small and you don't have a lot of users, it will not make much difference.
The more efficient way is to use getrows() and create an array.
' create a query/view with only the fields you will use
<%
'create rsLookup LookUpID, Lookup, LookUpParentID
sql="select * from myTable"
%>
<table>
<%
if not rsLookup.bof or not rsLookup.eof then
do until rsLookup.eof
%>
<tr>
<td><a href="#">View</a></td>
<td><a href="#">Edit</a></td>
<td><a href="#">Copy</a></td>
<td><a href="#">Delete</a></td>
<td><%=LookupID%></td>
<td><%=Lookup%></td>
<td><%=LookupParentID%></td>
</tr>
<%
rsLookup.movenext
Loop
end if
%>
</table>
The more efficient way is to use getrows() and create an array.
' create a query/view with only the fields you will use
if not rs.eof or not rs.bof then
myArray=rs.getrows()
end if
' in this case you have 3 fields and arrays are zero based
for x = 0 to ubound(MyArray,2)
theRow="<tr>"
theRow=Row&"<td><a href=""#"">View</a></td>"
theRow=Row&"<td><a href=""#"">Edit</a></td>"
theRow=Row&"<td><a href=""#"">Copy</a></td>"
theRow=Row&"<td><a href=""#"">Delete</a></td>"
theRow=Row&"<td>"&MyArray(0,x)&"</td>"
theRow=Row&"<td>"&MyArray(1,x)&"</td>"
theRow=Row&"<td>"&MyArray(2,x)&"</td>"
theRow=Row&"</tr>"
response.write theRow 'just one response.write per row. With proper logic, you can built the entire table this way and have just one response.write for the entire table.
next
XGIS,
You might find this helps you to formulate better questions and make it easier for Experts to help you.
Cd&
You might find this helps you to formulate better questions and make it easier for Experts to help you.
Cd&
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Good luck with that
ASKER
Solved by XGIS
Open in new window
Or you could place your files in jsbin or jsfiddle http://jsfiddle.net/pravee
Or you could have a working sample on your own site and link to that.
As far as your question, it is confusing, "The support staff sent me the following code to include on the "Row_Inserting" server event. It works if you place in the Parent ID value in, but I want that to be parsed without the need for user intervention. The user ONLY needs to add the Lookup name."
What exactly does this script do? It looks like it is meant to add look up items on the admin end? How can it do something without user intervention? If I enter the lookup name, what is supposed to happen?
From your 2nd image, it looks like you click on the link, "Add Look Up ID". You then get a pop up to add the lookup field and ID it is supposed to link to. Are you asking to have the link ID auto populated? If that is the case, you simply need to add <%=theID%> to the form field like, <input name="somename" type="text" value="<%=theID%>">. You will grab the id code I assume from the same place you see the Site ID in the light purple area (the number 1).
You will probably have to do some hand coding for this. That is one of the problems with code generators. They can only do so much without becoming more overly complex then they already are.