Add Drop Down TO ACCESS

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mbm2000
    New Member
    • Jul 2008
    • 12

    Add Drop Down TO ACCESS

    Hi
    I want to add a dropdown Menu to my ACCESS database With ASP
    Please Help Me
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #2
    Hi mbm2000,

    To populate a drop down list from a database in ASP you can do the following:
    Code:
     <% 
    'Initialise the recordset and connection objects and open the connection
    Dim oRS, oConn, sSQL
    Set oConn = Server.CreateObject("ADODB.Connection")
    oConn.Open CONNECTION_STRING
    Set oRS = Server.CreateObject ("ADODB.Recordset")
     
    'Define the SQL used to query the database
    sSQL = "SELECT ValueColumn, NameColumn FROM Table1 WHERE id = 1"
     
    'Open the recordset
    oRS.Open sSQL, oConn, 3
     
    Response.Write "<select name='dropdown1'>"
     
    'Loop through the recordset, writing an option for each row
    Do Until oRS.EOF
    	 Response.Write "<option value='" & oRS("ValueColumn") & ">"
    	 Response.Write oRS("NameColumn")
    	 Response.Write "</option>"
    	 oRS.MoveNext
    Loop
     
    Response.Write "</select>"
     
    'Destroy the objects
    Set oRS = Nothing
    oConn.Close
    Set oConn = Nothing
    %>
    Does this help at all? Let me know.

    Dr B

    Comment

    • mbm2000
      New Member
      • Jul 2008
      • 12

      #3
      HI DR B
      I want put this data to my access db
      I use This code for Drop Down Menu
      Code:
      <select size="1" name="star"value="<%= star %>">
          <option selected>0</option>
          <option>1</option>
          <option>2</option>
          <option>3</option>
          <option>4</option>
          <option>5</option>
          <option>6</option>
          <option>7</option>
        </select>
      and This Code For proccess
      Code:
      <!--#include file="header.asp"-->
      <% 
      On Error Resume Next
      If Request.Cookies("user_logged_ID" & strSUnique) = Empty then Response.Redirect "register.asp"
      If Request.Form("catID") = Empty Or Request.Form("subcatID") = Empty then Response.Redirect "post_new1.asp"
      If isnotfree And Not Request.Cookies("allow_post" & strSUnique) = "True" then Response.Redirect "filter.asp?url=post_new1.asp&act=startOver"
      
      If isnotfree then
      	set rs = objConn.Execute("SELECT credits FROM " & tablUPfx & "User WHERE userID = " & CLng(session("user_logged_ID" & strSUnique)) & ";")
      	If not rs.EOF then Session("user_logged_credit" & strSUnique) = FormatNumber(CCur(rs("credits")), 2)
      	rs.close
      	If CCur(Request.Cookies("final_price" & strSUnique)) > CCur(Session("user_logged_credit" & strSUnique)) Then 
      		Response.Write strText_NotEnoughCredits
      		Response.End
      	End If
      End If
      
      
      Dim msg, star
      setLocale server_locale
      sdd = dd(objConn)
      
      userID = CLng(Request.Cookies("user_logged_ID" & strSUnique))
      postExpire = DateAdd("d", CLng(Request.Form("S1")), Now)
      
      
      star = Request.form("star")
      
      IP = Request.ServerVariables("REMOTE_ADDR")
      adID = subcatID & RandomNumber & userID
      adID = CStr(adID)
      If moderate then active = 0: Else: active = 1
      If len(subject) > 0 and Len(descr) > 0 Then
      
      If not Request.Form("imgFile") = Empty then
      	img = sq(Request.Form("imgFile"))
      	imgArray = Split(img, sf)
      	For d = 0 to UBound(imgArray) - 1
      		imgName = Split(imgArray(d), "|")(0)
      		set rs = objConn.Execute("SELECT " & tablPfx & "Temp.tempimg FROM " & tablPfx & "Temp WHERE tempimg = '" & imgName & "';")
      		If Not rs.EOF then objConn.Execute("DELETE FROM " & tablPfx & "Temp WHERE tempimg = '" & imgName & "';")
      		rs.close
      	Next
      End If
      
      If isnotfree then 
      	hotlist = Request.Cookies("hotlist" & strSUnique)
      	'If Len(img) > 0 then
      		userimglimit = Request.Cookies("image_limit" & strSUnique)
      	'Else: userimglimit = 0		
      	'End If
      Else
      	userimglimit = imagelimit
      	hotlist = 0
      End If
      
      For uo = 0 to 7
      	nextUserFormText = Request.Form("uO" & uo)
      	If Len(nextUserFormText) = 0 then nextUserFormText = Request.Form("uCOF" & uo)
      	strUserValues = strUserValues & ", '" & sq(HTMLEncode(nextUserFormText)) & "'"	
      	strUserFields = strUserFields & ", " & "uopt" & uo + 1
      Next
      
      For o = 1 to 20
      	nextFormText = Request.Form("O" & o)
      	If Len(nextFormText) = 0 then nextFormText = Request.Form("COF" & o)
      	nextFormText = Replace(Replace(nextFormText, "<", "&lt;"), ">", "&gt;")
      	nextFormText = sq(HTMLEncode(nextFormText))
      	strCatValues = strCatValues & ", '" & nextFormText & "'"
      	strCatFields = strCatFields & ", " & "opt" & o
      Next
      
      strSQL = "INSERT INTO " & tablPfx & "Ads(adID, catID, scatID, cat3rdID, userID, pdate, edate, nick, city, subject, phone, web, images, webimage, body, status, IP, adcounter, hotlist, price"
      strSQL = strSQL & strUserFields & strCatFields & ", userimagelimit) VALUES ('" & adID & "', " & catID & ", " & subcatID & ", " & cat3rdID & ", " & userID & ", " & sdd & PostPosted & sdd & ", " & sdd & postExpire & sdd & ", '" & nick & "', "
      strSQL = strSQL & "'" & city & "', '" & subject & "', '" & phone & "', '" & URL & "', '" & img & "', '" & onlineImg & "', '" & descr & "', " & active & ", '" & IP & "', "
      strSQL = strSQL & 0 & ", " & hotlist & ", '" & star & "', '" & price & "'" & strUserValues & strCatValues & ", " & userimglimit & ");"
      
      objConn.Execute(strSQL)
      
      Call updateUserPostData(userID, adID, price, "postnew")
      
      If moderate then
      	Call getTemplate("New_Ad_Pending", email, Empty, nick, Empty, adID)
      Else
      	Call UpdateList(True, catID, subcatID, cat3rdID)
      	Call getTemplate("New_Ad_Approved", email, Empty, nick, Empty, adID)
      	Application("cl_marquee" & strUnique) = Empty
      	Call matchAlerts(adID, catID, subcatID, cat3rdID, subject, descr)
      End If
      
      If IsCache then Call cacheAds(adID)
      
      Call sendEmail(email, notify_email, uSubject, uBody)
      Call getTemplate("Admin_Notify", email, Empty, nick, Empty, adID)
      Call sendEmail(admin_email, notify_email, uSubject, uBody)
      If isEvents then Call logEvent("New Ad", adID, subject, Empty, Empty, Empty)
      
      Response.Cookies("user_logged_ID" & strSUnique) = Empty
      Session("image_limit" & strSUnique) = Empty
      Session("duration_limit" & strSUnique) = Empty
      Session("hotlist" & strSUnique) = Empty
      Session("allow_post" & strSUnique) = Empty
      Session("final_price" & strSUnique) = Empty
      session("Select_Category" & strSUnique) = Empty
      session("Select_SubCategory" & strSUnique) = Empty
      session("Select_CategoryID" & strSUnique) = Empty
      session("Select_SubCategoryID" & strSUnique) = Empty
      session("Select_3rdCategory" & strSUnique) = Empty
      session("Select_3rdCategoryID" & strSUnique) = Empty
      Session("Attach_Image" & strSUnique) = Empty
      Set session("Attach_Image" & strSUnique) = Nothing
      Set session("Temp_UserArray" & strSUnique) = Nothing
      Session("Count_Image" & strSUnique) = Empty
      
      
      Response.Write "<br><div align='center'>" & strText_Posted & "&nbsp;<b>" & email & "</b></div><br>"
      If moderate then Response.Write "<div align='center'>" & strText_Posted1 & "</div><br>"
      End If
      %><!--#include file="tneval_footer.asp"--><!--#include file="footer.asp"-->
      Thanks alot DR B

      Comment

      • DrBunchman
        Recognized Expert Contributor
        • Jan 2008
        • 979

        #4
        Sorry, I'm a bit confused - what is the actual problem?

        Comment

        • mbm2000
          New Member
          • Jul 2008
          • 12

          #5
          Hi DR B
          I use the First code for Drop down Menu and the Second code for process it
          but no data Insert In The DataBase
          Thanks alot

          Comment

          • DrBunchman
            Recognized Expert Contributor
            • Jan 2008
            • 979

            #6
            I see!

            The first thing to do is to remove any error trapping: comment out the On Error Resume Next line and try again - do you get any errors?

            Dr B

            Comment

            • mbm2000
              New Member
              • Jul 2008
              • 12

              #7
              Hi What Is error trapping?
              please say more
              I want the complete Sourse Of This dropdown
              [HTML]<select><option >1</option></select>[/HTML]

              Comment

              Working...