• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

populate if the database record already has a value for the field.

Hello,

I would like to ask for help in figuring out how to populate a drop down menu with an existing value from db, and also displaying all the other values available in case that the current values needs to be changed.

Context:

Form field Order Status is formed by appending 5 record set fields: Box_Nbr, Line_No, Part_ID, Heat_No, Bndl_Pc_Cnt.

The record set is retrieved  by order id.

The page before the landing page, passes only one variable through the query-string. I would like to know if there is a quick way to do it, without having to pass all the needed values on the URL.

I am attaching my current code.

Thank you so much.
<select name="myBoxNbr_Select" size="1" onchange="javascript:updateBoxNbr();">
                              <option></option>
                              <option value="X"%><%="BX|LN | PART ID..................................| HEAT .|CNT"%></option>
				            <%

                            Set cn2 = Server.Createobject("ADODB.Connection")
                            cn2.Open ConnectionString
                            Sql = "Select Box_Nbr, Line_No, Part_ID, Heat_No, Bndl_Pc_Cnt from Label where Order_ID='" & Order_ID & _
                                  "' Order By Box_Nbr, Line_No, Bndl_Pc_Cnt"
                            Set rsData2 = cn2.Execute(Sql)
                            On Error Resume Next
                            rsData2.MoveFirst
                            do while not rsData2.eof


                              Order_Item = AddLeadingZeros(rsData2.fields("Box_Nbr"), 2) & " | " & _
							               AddLeadingZeros(rsData2.fields("Line_No"), 2) & " | " & _
							               rsData2.fields("Part_ID") & " | " & _
                                           rsData2.fields("Heat_No") & " | " & _
							               AddLeadingZeros(rsData2.fields("Bndl_Pc_Cnt"),3)
                            %>
                              <option value="<%=rsData2.fields("Box_Nbr")%>" selected="selected"><%=Order_Item%></option>
                              
                            <%
                              rsData2.MoveNext
                            loop
                            rsData2.close
                            set rsData2 = Nothing
                            cn2.Close
                            set cn2 = Nothing
                            %>
				            </select>

Open in new window

0
metropia
Asked:
metropia
  • 3
  • 2
1 Solution
 
Wayne BarronCommented:
Something like this.
Create a new RecordSet that contains the values of the current records
rsData1
Then do this

<select name="">
<option value="<%=rsData1("MyValue")%>"><%=rsData1("MyValue")%></option>
<%while not rsData2.eof%>
<option value="<%=rsData2("Box_Nbr")%>"><%=Order_Item%></option>
<%rsData2.movenext
wend
rsData2.close%>
</select>

Open in new window


Carrzkiss
0
 
metropiaAuthor Commented:
Will this second record set be place below the current record set, within the do while that already is in place?

Thanks!
0
 
metropiaAuthor Commented:
I was looking at the second solutions on this page:

http://www.powerasp.com/content/code-snippets/forms-populate-drop-down-menu.asp

I have not been able to successfully do a request.form of the values of the previous page, likely because the values are in this format (I think):

<td><div class="table-cell-values-style"><a href="LabelEdit.asp?Label_ID=<%=rsData.fields("Label_ID")%>&Box_Nbr=<%=rsData.fields("Box_Nbr")%>&Reprint=Yes"><%=rsData.fields("Box_Nbr")%></a></div></td>

Contrary to the way they show on the second example, values are stored on input fields.

I hope this makes sense.

Thanks again!
0
 
Wayne BarronCommented:
Here is the code within your existing code.
You will need to create the other RecordSet that goes with the order id
Once the page is shown, then the ID that corresponds with the Selected option, it will show.

If you are having difficulties following this, or making it work.
Please provide me with an example Database, with some example records in it, and I will make you up a demo on how to use it.

Just make the demo work with your existing example that you have posted here.
 

<select name="myBoxNbr_Select" size="1" onchange="javascript:updateBoxNbr();">
<option value="<%=rsData1("MyValue")%>"><%=rsData1("MyValue")%></option>
<option value="X"%><%="BX|LN | PART ID..................................| HEAT .|CNT"%></option>
<%

Set cn2 = Server.Createobject("ADODB.Connection")
cn2.Open ConnectionString
Sql = "Select Box_Nbr, Line_No, Part_ID, Heat_No, Bndl_Pc_Cnt from Label where Order_ID='" & Order_ID & _
      "' Order By Box_Nbr, Line_No, Bndl_Pc_Cnt"
Set rsData2 = cn2.Execute(Sql)
On Error Resume Next
rsData2.MoveFirst
do while not rsData2.eof


Order_Item = AddLeadingZeros(rsData2.fields("Box_Nbr"), 2) & " | " & _
AddLeadingZeros(rsData2.fields("Line_No"), 2) & " | " & _
rsData2.fields("Part_ID") & " | " & _
               rsData2.fields("Heat_No") & " | " & _
AddLeadingZeros(rsData2.fields("Bndl_Pc_Cnt"),3)
%>
  <option value="<%=rsData2.fields("Box_Nbr")%>" selected="selected"><%=Order_Item%></option>
  
<%
  rsData2.MoveNext
loop
rsData2.close
set rsData2 = Nothing
cn2.Close
set cn2 = Nothing
</select>

Open in new window

0
 
metropiaAuthor Commented:
Thanks a lot!
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now