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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combo. 1

Status
Not open for further replies.

svsuthar1

Programmer
Jul 6, 2004
135
US
Hi..

How would I change this code to do combo box that uses my recordset. The form uses multiple entry form. The code below is for text I wanted to change it to combo.

Response.Write("<TD><input type=text name=""" & _
iCount & ".Quantity"" Value=0 STYLE=text-align:center></TD>")
 
Here is the full code...if that helps you understand what I want.

Dim objConn, path
path="C:\Inetpub\
'Create a Connection using the path given above
Set objconn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString= "PROVIDER=MICROSOFT.JET.OLEDB.4.0;" & _
"DATA SOURCE=" & path
objConn.Open

'Create the SQL to be used for it to display
Dim strSQL, strSQL1, objRS, objRS1, iCount
iCount = 0
strSQL = "SELECT tblProducts.fldProductID, tblProducts.fldOrderNum, tblProducts.fldProductName, tblProducts.fldActive, tblCategory.fldCategoryID " _
& "FROM tblCategory INNER JOIN tblProducts ON tblCategory.fldCategoryID = tblProducts.fldCategoryID " _
& "WHERE (((tblProducts.fldActive)=Yes) AND ((tblCategory.fldCategoryID)=" & Request.QueryString("CategoryID")& "));"

strSQL1 = "SELECT fldActionID, fldActionName " _
& "FROM tblAction"

'Create a recordset of the SQL that is created above
Set objRS = Server.CreateObject("ADODB.Recordset")
Set objRS1 = Server.CreateObject("ADODB.Recordset")
objRS.Open strSQL, objConn,3,3
objRS1.Open strSQL1, objConn,3,3

'loop through all the records outputting a row for each one
Do Until objRS.EOF
Response.Write("<TR>")
Response.Write("<Input Type=Hidden Name=""" & iCount & ".ID"" " & _
"Value=""" & objRS("fldProductID") & """>")
Response.Write("<TD align=Center>" & objRS("fldOrderNum") & "</TD>")
Response.Write("<TD>" & objRS("fldProductName") & "</TD>")
Response.Write("<TD><input type=text name=""" & _
iCount & ".Price"" Value=0 STYLE=text-align:center></TD>")
Response.Write("<TD><input type=text name=""" & _
iCount & ".Quantity"" Value=0 STYLE=text-align:center></TD>")
Response.Write("<TD><input type=text name=""" & _
iCount & ".Action"" Value=0 STYLE=text-align:center></TD>")
Response.Write("<TD><input type=text name=""" & _
iCount & ".Date"" Value=0 STYLE=text-align:center></TD>")
Response.Write("</TR>")
objRS.MoveNext
iCount = iCount + 1
Loop
'Clean up our ADO objects
objRS.Close
Set objRS = Nothing

objConn.Close
Set objConn = Nothing
Response.Write "<TR><TD Align=Center colspan=6><INPUT TYPE=BUTTON VALUE=""Submit"" ONCLICK=""SaveOrder();"" id=BUTTON1 name=BUTTON1></TD></TR>"
Response.Write "<INPUT TYPE=HIDDEN NAME=Count VALUE=" & iCount - 1 & ">
 
Code:
response.write("<SELECT Name='myCombo'>")
Do while not objRS1.eof
   ActionID = objRS1("fldActionID")
   ActionName = objRS1("fldActionName")
   response.write("<option value='" & ActionID & "'>" & ActionName & "</option>"
   objRS1.movenext  
Loop
response.write("</Select>")
 
I know the this part of the code, but how would I incorprate the iCount since this is multi item form.

I am talking about the bolded part below...

Response.Write("<TD><input type=text name=""" & _
iCount & ".Date"" Value=0 STYLE=text-align:center></TD>")


 
Do it exactly the same way you are handling your textboxes.
<select name=""" & iCount & etc....
I take it that you're creating a new set of controls for every record in objRS? Don't forget to close objRS1 at the bottom of that loop. You're going to have to open it up again on each pass through objRS.
 
Thanks Veep,

Can you help me write the syntax for that I am having problem writing... I have tried many ways but i keep on having problems... here is part of my code.

Response.Write("<TD><Select name=""" & iCount & ".Action"">" & _
Do While Not objRS1.EOF
<OPTION value=objRS1("fldErrorID")>objRS1("fldErrorCode")</OPTION>
objRS1.MoveNext
Loop
</SELECT></TD>")
 
Do you mean the loop? Assign your values to variables. It's easier to look at.
Code:
Response.Write("<TD><Select name=""" & iCount & ".Action"">"
Do While Not objRS1.EOF
    ID = objRS1("fldErrorID")
    Code = objRS1("fldErrorCode")
    response.write("<option value='" & ID & "'>" & Code & "</option>"
    objRS1.movenext
Loop
response.write("</select></td>")
objRS1.Close
set objRS1 = nothing
 
It gives me object Required... When I took the objRS1.Close and Set objRS1 = Nothing away it worked, but only for the first record and gave me blank combo for the rest.

I am not sure why...

any idea.

Samir
 
Should look something like this.
Code:
'Create a recordset of the SQL that is created above  
Set objRS = Server.CreateObject("ADODB.Recordset")
Set objRS1 = Server.CreateObject("ADODB.Recordset")
    objRS.Open strSQL, objConn,3,3
    objRS1.Open strSQL1, objConn,3,3
        
    'loop through all the records outputting a row for each one
     Do Until objRS.EOF    
        Response.Write("<TR>")
[red]Response.Write("<TD><Select name=""" & iCount & ".Action"">"
Do While Not objRS1.EOF
    ID = objRS1("fldErrorID")
    Code = objRS1("fldErrorCode")
    response.write("<option value='" & ID & "'>" & Code & "</option>"
    objRS1.movenext
Loop
response.write("</select></td>")
objRS1.Close
set objRS1 = nothing[/red]           

        Response.Write("<Input Type=Hidden Name=""" & iCount & ".ID"" " & _
                        "Value=""" & objRS("fldProductID") & """>")
        Response.Write("<TD align=Center>" & objRS("fldOrderNum") & "</TD>")
        Response.Write("<TD>" & objRS("fldProductName") & "</TD>")
        Response.Write("<TD><input type=text name=""" & _
            iCount & ".Price"" Value=0 STYLE=text-align:center></TD>")
        Response.Write("<TD><input type=text name=""" & _
            iCount & ".Quantity"" Value=0 STYLE=text-align:center></TD>")
        Response.Write("<TD><input type=text name=""" & _
            iCount & ".Action"" Value=0 STYLE=text-align:center></TD>")
        Response.Write("<TD><input type=text name=""" & _
            iCount & ".Date"" Value=0 STYLE=text-align:center></TD>")
        Response.Write("</TR>")
        objRS.MoveNext
        iCount = iCount + 1
     Loop
'Clean up our ADO objects
objRS.Close
Set objRS = Nothing

objConn.Close
Set objConn = Nothing
Response.Write "<TR><TD Align=Center colspan=6><INPUT TYPE=BUTTON VALUE=""Submit"" ONCLICK=""SaveOrder();"" id=BUTTON1 name=BUTTON1></TD></TR>"
Response.Write "<INPUT TYPE=HIDDEN NAME=Count VALUE=" & iCount - 1 & ">"
 
That is the same place I have kept the code. I am not sure then why it's not working.

Samir
 
What I am trying to do is it possible. It should be I have seen this on other pages. I am so close... just not there?
 
From what I understand you're trying to loop through a recordset (objRs). For each record in objRS you want to create a series of textboxes and whathaveyous and a combo box (from another recordset). Right? The series of events that happens here is:
Code:
[red]'Open Connection[/red]
Set conn = Server.CreateObject("ADODB.Connection")
myConnString = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;" & _           
                              "DATA SOURCE=" & path 
conn.open myConnString
iCount = 0
    strSQL = "SELECT tblProducts.fldProductID, tblProducts.fldOrderNum, tblProducts.fldProductName, tblProducts.fldActive, tblCategory.fldCategoryID " _
        & "FROM tblCategory INNER JOIN tblProducts ON tblCategory.fldCategoryID = tblProducts.fldCategoryID " _
        & "WHERE (((tblProducts.fldActive)=Yes) AND ((tblCategory.fldCategoryID)=" & Request.QueryString("CategoryID")& "));"
SET rs = conn.execute(strSql)
If not rs.eof then
[red]'loop through the main recordset[/red]
strSql1 = "SELECT fldActionID, fldActionName FROM tblAction"
Do While Not RS.EOF    
        Response.Write("<TR>")
Response.Write("<TD><Select name=""" & iCount & ".Action"">"
[red]'Create the combo box recordset[/red]
SET rs1 = conn.execute(strSql1)
Do While Not RS1.EOF
    ID = RS1("fldErrorID")
    Code = RS1("fldErrorCode")
    response.write("<option value='" & ID & "'>" & Code & "</option>"
    RS1.movenext
Loop
response.write("</select></td>")
[red]'Set it to nothing cause we're going to need 
'to create it again the next time around[/red]
set RS1 = nothing           

        Response.Write("<Input Type=Hidden Name=""" & iCount & ".ID"" " & _
                        "Value=""" & RS("fldProductID") & """>")
        Response.Write("<TD align=Center>" & RS("fldOrderNum") & "</TD>")
        Response.Write("<TD>" & RS("fldProductName") & "</TD>")
        Response.Write("<TD><input type=text name=""" & _
            iCount & ".Price"" Value=0 STYLE=text-align:center></TD>")
        Response.Write("<TD><input type=text name=""" & _
            iCount & ".Quantity"" Value=0 STYLE=text-align:center></TD>")
        Response.Write("<TD><input type=text name=""" & _
            iCount & ".Action"" Value=0 STYLE=text-align:center></TD>")
        Response.Write("<TD><input type=text name=""" & _
            iCount & ".Date"" Value=0 STYLE=text-align:center></TD>")
        Response.Write("</TR>")
        RS.MoveNext
        iCount = iCount + 1

Loop
RS.Close
Set RS = Nothing
End If
I still see some possible HTML issues but that should work.
 
Veep,

Thank you, I have tried and put the second recordset and connection within the first loop and it worked.

Thank you all for your help.. I really appreciate all the efforts that went into this post. You all deserve 5 stars.

Samir
 
sorry I checked for the names later and I found it was all you Veep...Sorry but thank you for sticking with me.

Samir
 
Hello svsuthar1,

You know what to do? At lower left side of any of Veep's posting, click "Thank Veep fo this valuable posting" and confirm the popup.

regards - tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top