|
 |
access_asp thread: Filling Option Menu Via Access table
Message #1 by "Aaron Redding" <aredding@b...> on Fri, 14 Jun 2002 06:05:34
|
|
Ok I'm having difficulty in figuring the code for filling a drop down
option menu with names when I edit a record. What I want to acomplish is
this. If a user creates adds a new record, the drop down menu will be
filled with "agent" names which are stored in the DB as numbers. So
agent "redding, aaron" is agent number 3. ok that part I know how to do,
but now using the same form, a user wants to edit that record. now I
want the "agent" drop down menu to have the current agent as the option
selected..and fill the rest of the form with the rest of the agents. So
that is where I am stuck, would it be a filter? or soemthing totally
different.
Thanks for any help
Aaron
Message #2 by "Kevin" <yabmod@e...> on Fri, 14 Jun 2002 16:14:37
|
|
> Ok I'm having difficulty in figuring the code for filling a drop down
o> ption menu with names when I edit a record. What I want to acomplish
is
t> his. If a user creates adds a new record, the drop down menu will be
f> illed with "agent" names which are stored in the DB as numbers. So
a> gent "redding, aaron" is agent number 3. ok that part I know how to
do,
b> ut now using the same form, a user wants to edit that record. now I
w> ant the "agent" drop down menu to have the current agent as the option
s> elected..and fill the rest of the form with the rest of the agents. So
t> hat is where I am stuck, would it be a filter? or soemthing totally
d> ifferent.
> Thanks for any help
> Aaron
Message #3 by "Kevin" <yabmod@e...> on Fri, 14 Jun 2002 16:46:38
|
|
> Aaron
This is how I do it....
assuming objrs is your recordset run a query which returns the records
current value to the field you're working with
<select name="whatever">
<%
response.write "<option selected value=""" & objrs.fields("agent_no")
& """ selected>" & objrs.fields("agent_name") & "</option>"
' that will put the current value in the box and make it the first value on
' the top of the list
' Now either close the current recordset or open a new one and retrieve
' all of the other values then for the rest of the list, I would assume you
' would leave it open to populate more fields
objrs1.open "select * from agents where agent_no <>="& objrs.fields
(agent_no) &" order by agent_name ", objconn, 0, 1
' where prevents name from showing twice
Do while not objrs1.eof
response.write "<option value=""" & objrs1.fields("agent_no") & """>" &
objrs1.fields("agent_name") & "</option>"
loop
%>
</select>
Message #4 by Karri Peterson <KPeterson@C...> on Fri, 14 Jun 2002 10:41:09 -0500
|
|
Has anybody out there been doing anything with ASP.net?
I have some apps I have been thinking about converting--wondered if anyone
had any thoughts on it.
Karri
-----Original Message-----
From: Kevin [mailto:yabmod@e...]
Sent: Friday, June 14, 2002 11:47 AM
To: Access ASP
Subject: [access_asp] Re: Filling Option Menu Via Access table
> Aaron
This is how I do it....
assuming objrs is your recordset run a query which returns the records
current value to the field you're working with
<select name="whatever">
<%
response.write "<option selected value=""" & objrs.fields("agent_no")
& """ selected>" & objrs.fields("agent_name") & "</option>"
' that will put the current value in the box and make it the first value on
' the top of the list
' Now either close the current recordset or open a new one and retrieve
' all of the other values then for the rest of the list, I would assume you
' would leave it open to populate more fields
objrs1.open "select * from agents where agent_no <>="& objrs.fields
(agent_no) &" order by agent_name ", objconn, 0, 1
' where prevents name from showing twice
Do while not objrs1.eof
response.write "<option value=""" & objrs1.fields("agent_no") & """>" &
objrs1.fields("agent_name") & "</option>"
loop
%>
</select>
Message #5 by "Ken Schaefer" <ken@a...> on Mon, 17 Jun 2002 13:47:30 +1000
|
|
Lots of people have :-)
http://p2p.wrox.com has plenty of ASP.Net lists
Cheers
Ken
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "Karri Peterson" <KPeterson@C...>
Subject: [access_asp] Re: Filling Option Menu Via Access table
: Has anybody out there been doing anything with ASP.net?
:
: I have some apps I have been thinking about converting--wondered if anyone
: had any thoughts on it.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Message #6 by "Ken Schaefer" <ken@a...> on Mon, 17 Jun 2002 13:49:36 +1000
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "Kevin" <yabmod@e...>
Subject: [access_asp] Re: Filling Option Menu Via Access table
:
: > Aaron
:
: This is how I do it....
:
: assuming objrs is your recordset run a query which returns the records
: current value to the field you're working with
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Here is, in my humble opinion, a better way to do it :-)
a) Run a query that returns a list of "agents" and their AgentIDs.
b) Use .GetRows to turn that into a VBScript array.
c) Pass the array (with the rest of parameters) to the following routine,
which will return the necessary HTML, with the appropriate element selected
(watch for wrapping):
------------------------------------------------------------
' WriteFormSelectList
'------------------------------------------------------------
' Returns HTML for a <select> element
' Accepts strName as string
' Accepts strID as string
' Accepts strHTMLAttributes as string - literal text for any other HTML
attributes
' Accepts form option elements as array
' Accepts array format as integer: 0 = rows/cols, 1 = cols/rows (eg from
getRows)
' Accepts optional text for first <option></option> tag
' Accepts strSelectedValue as option to be selected
'------------------------------------------------------------
Function WriteFormSelectList( _
ByVal strName, _
ByVal strID, _
ByVal strHTMLAttributes, _
ByVal arrOptions, _
ByVal intArrayFormat, _
ByVal strFirstOption, _
ByVal strSelectedValue _
)
Dim i ' array 1st dimension counter
If not isArray(arrOptions) then
Exit Function
End If
WriteFormSelectList = "<select name=""" & strName & """ ID=""" & strID &
""""
If Len(strHTMLAttributes & "") > 0 then
WriteFormSelectList = WriteFormSelectList & " " & strHTMLAttributes & """"
End If
WriteFormSelectList = WriteFormSelectList & ">" & vbCrLf
If Len(strFirstOption) > 0 then
WriteFormSelectList = WriteFormSelectList & strFirstOption & vbCrLf
End If
If intArrayFormat = 0 then
For i = 0 to Ubound(arrOptions, 1)
WriteFormSelectList = WriteFormSelectList & "<option value=""" &
arrOptions(i,0) & """>" & arrOptions(i,1) & "</option>" & vbCrLf
Next
Else
For i = 0 to Ubound(arrOptions, 2)
WriteFormSelectList = WriteFormSelectList & "<option value=""" &
arrOptions(0,i) & """>" & arrOptions(1,i) & "</option>" & vbCrLf
Next
End If
WriteFormSelectList = WriteFormSelectList & "</select>" & vbCrLf
If Len(strSelectedValue & "") > 0 then
WriteFormSelectList = Replace(WriteFormSelectList, "value=""" &
strSelectedValue & """>", "value=""" & strSelectedValue & """ selected>")
End If
End Function
'------------------------------------------------------------
' --- WriteFormSelectList
'------------------------------------------------------------
|
|
 |