here some code that will build a dropbox on a webpage just by
call BuildDrop(FieldName, TableName,pick,Action)
I use it all the time
sorry about the code been misse
Code:
Sub BuildDrop(FieldName, TableName,pick,Action)
'**************************************
'This Will build a Dropbox in a Web site
'Base on a Database Feild
'**************************************
' ReWrite this Function To handle -1
' rule with this is Autonumber must have same name as table
' use Query to get it right.
Dim IsItSelected
Dim SQL, ID , IDF , Picked2 , Picked , rsBuildDrop , IID , IDD , SS
Dim OutputLine
ID = TableName & "ID"
IDF = FieldName
Picked = Picked2
if pick="" then pick=" "
Set rsBuildDrop = Server.CreateObject("ADODB.Recordset")
sql = ""
if VarType(pick) = 8 then '8 = string
sql = sql & "SELECT " & TableName & "." & FieldName
sql = sql & " FROM " & TableName & " "
SQL = SQL & " GROUP BY " & TableName & "." & FieldName
SQL = SQL & " ORDER BY " & TableName & "." & FieldName & ";"
else
sql = sql & "SELECT " & TableName & "." & TableName & "ID ," & TableName & "." & FieldName
sql = sql & " FROM " & TableName & " "
SQL = SQL & " GROUP BY " & TableName & "." & FieldName & "," & TableName & "." & TableName & "ID"
SQL = SQL & " ORDER BY " & TableName & "." & TableName & "ID;"
End if
rsBuildDrop.Open SQL, connstring, adOpenKeyset, adLockPessimistic, adCmdText
if VarType(pick) = 8 then
Picked = rsBuildDrop.Fields(FieldName)
IID = IDF
IDD = "Please Select"
SS = ""
else
Picked = rsBuildDrop.Fields(ID)
IID = ID
IDD = "0"
SS = "selected"
end if
Response.write vbnewline & "<select name=""" & IID & """ " & Action &" >" & vbnewline
Response.Write "<option " & " value="""& IDD & """ "& SS & " >Please Select</option>" & vbnewline
Do Until rsBuildDrop.EOF
if VarType(pick) = 8 then
Picked = rsBuildDrop.Fields(FieldName)
else
Picked = rsBuildDrop.Fields(ID)
end if
if pick = rsBuildDrop.Fields(0) then
SS = "selected"
else
SS = ""
End if
OutputLine = "<option " & SS & " value=""" & Picked & """ >" & trim(rsBuildDrop.Fields(FieldName)) & "</option>" & vbnewline
Response.write OutputLine
rsBuildDrop.movenext
loop
rsBuildDrop.close
set rsBuildDrop = nothing
Response.write "</select>" & vbnewline
if VarType(pick) = 8 then
Response.write "Or <INPUT type=""text"" id=""S" & IDF & """ name=""S" & IDF & """ size=15 value=""" & trim(" ") & """>"
else
END IF
End Sub
Some rule are the primerykey must have the same name as the tablename
eg tablename Books
the primary key has to be named booksID
you can make querys to match the Rules