Setting drop-down box to database value

L

Lisa

Hi,

I have an .asp page that loads a MS Access database from a form, one of the
fields, Total_Hours is a drop-down box. Now I need an update page to allow
the user to change the Total_Hours, so I need to set the drop-down value to
the value stored in the database. How/where can I set this up so the field
could be changed before saving back to the database?

<select size="1" name="Total_Hours">
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
</select></tr>

Lisa
 
S

Stefan B Rusynko

Open your db/rs and get the field - say TotalHrs

Then Add it as your 1st field
<select size="1" name="Total_Hours">
<option value="<%=objrs("TotalHrs")%>"><%=objrs("TotalHrs")%></option>
<option>0</option>
......

See http://www.asp101.com/samples/db_edit.asp
--

_____________________________________________
SBR @ ENJOY (-: [ Microsoft MVP - FrontPage ]
"Warning - Using the F1 Key will not break anything!" (-;
_____________________________________________


| Hi,
|
| I have an .asp page that loads a MS Access database from a form, one of the
| fields, Total_Hours is a drop-down box. Now I need an update page to allow
| the user to change the Total_Hours, so I need to set the drop-down value to
| the value stored in the database. How/where can I set this up so the field
| could be changed before saving back to the database?
|
| <select size="1" name="Total_Hours">
| <option>0</option>
| <option>1</option>
| <option>2</option>
| <option>3</option>
| <option>4</option>
| <option>5</option>
| <option>6</option>
| <option>7</option>
| <option>8</option>
| <option>9</option>
| <option>10</option>
| </select></tr>
|
| Lisa
|
 
L

Lisa

Hi,

That sort of works, but now I have the value in the list twice, so if the
number in the db was 4, the drop-down list now is 4,0,1,2,3,4,5,6... - any
way around this??

Lisa
 
T

Thomas A. Rowe

You would have to have a recordset that loads the values into the dropdown, then you would in your
SQL Select statement exclude the default value [objrs("TotalHrs")], in you example that would be
"4". Then your list would be 0,1,2,3,5,6, now this could lead to a problem if the user make a
selection of say "5" then changes their mind, they would not be able to put back the "4".

--
==============================================
Thomas A. Rowe
Microsoft MVP - FrontPage

http://www.Ecom-Data.com
==============================================


Lisa said:
Hi,

That sort of works, but now I have the value in the list twice, so if the
number in the db was 4, the drop-down list now is 4,0,1,2,3,4,5,6... - any
way around this??

Lisa

Stefan B Rusynko said:
Open your db/rs and get the field - say TotalHrs

Then Add it as your 1st field
<select size="1" name="Total_Hours">
<option value="<%=objrs("TotalHrs")%>"><%=objrs("TotalHrs")%></option>
<option>0</option>
......

See http://www.asp101.com/samples/db_edit.asp
--

_____________________________________________
SBR @ ENJOY (-: [ Microsoft MVP - FrontPage ]
"Warning - Using the F1 Key will not break anything!" (-;
_____________________________________________


| Hi,
|
| I have an .asp page that loads a MS Access database from a form, one of the
| fields, Total_Hours is a drop-down box. Now I need an update page to allow
| the user to change the Total_Hours, so I need to set the drop-down value to
| the value stored in the database. How/where can I set this up so the field
| could be changed before saving back to the database?
|
| <select size="1" name="Total_Hours">
| <option>0</option>
| <option>1</option>
| <option>2</option>
| <option>3</option>
| <option>4</option>
| <option>5</option>
| <option>6</option>
| <option>7</option>
| <option>8</option>
| <option>9</option>
| <option>10</option>
| </select></tr>
|
| Lisa
|
 
L

Lisa

Well, what I was thinking was more just from a pure programming background -
basically I thought there maybe a way to loop throught the options, and if i
= [objrs("TotalHrs")], then make it selected, or something along those
lines.....but maybe I am making it too complicated.

Lisa

Thomas A. Rowe said:
You would have to have a recordset that loads the values into the dropdown, then you would in your
SQL Select statement exclude the default value [objrs("TotalHrs")], in you example that would be
"4". Then your list would be 0,1,2,3,5,6, now this could lead to a problem if the user make a
selection of say "5" then changes their mind, they would not be able to put back the "4".

--
==============================================
Thomas A. Rowe
Microsoft MVP - FrontPage

http://www.Ecom-Data.com
==============================================


Lisa said:
Hi,

That sort of works, but now I have the value in the list twice, so if the
number in the db was 4, the drop-down list now is 4,0,1,2,3,4,5,6... - any
way around this??

Lisa

Stefan B Rusynko said:
Open your db/rs and get the field - say TotalHrs

Then Add it as your 1st field
<select size="1" name="Total_Hours">
<option value="<%=objrs("TotalHrs")%>"><%=objrs("TotalHrs")%></option>
<option>0</option>
......

See http://www.asp101.com/samples/db_edit.asp
--

_____________________________________________
SBR @ ENJOY (-: [ Microsoft MVP - FrontPage ]
"Warning - Using the F1 Key will not break anything!" (-;
_____________________________________________


| Hi,
|
| I have an .asp page that loads a MS Access database from a form, one of the
| fields, Total_Hours is a drop-down box. Now I need an update page to allow
| the user to change the Total_Hours, so I need to set the drop-down value to
| the value stored in the database. How/where can I set this up so the field
| could be changed before saving back to the database?
|
| <select size="1" name="Total_Hours">
| <option>0</option>
| <option>1</option>
| <option>2</option>
| <option>3</option>
| <option>4</option>
| <option>5</option>
| <option>6</option>
| <option>7</option>
| <option>8</option>
| <option>9</option>
| <option>10</option>
| </select></tr>
|
| Lisa
|
 
S

Stefan B Rusynko

That would require 10 separate IF statements if you want to do it
- cumbersome, but each option would be
<option value="0" <%IF objrs("TotalHrs")=0 Then%>selected<%End IF%>>0</option>
<option value="2" <%IF objrs("TotalHrs")=2 Then%>selected<%End IF%>>1</option>
.....


Better to just correct my example for the 1st option to be
<option value="<%=objrs("TotalHrs")%> selected"><%=objrs("TotalHrs")%></option>
<option>0</option>
......


--

_____________________________________________
SBR @ ENJOY (-: [ Microsoft MVP - FrontPage ]
"Warning - Using the F1 Key will not break anything!" (-;
_____________________________________________


| Well, what I was thinking was more just from a pure programming background -
| basically I thought there maybe a way to loop throught the options, and if i
| = [objrs("TotalHrs")], then make it selected, or something along those
| lines.....but maybe I am making it too complicated.
|
| Lisa
|
| "Thomas A. Rowe" wrote:
|
| > You would have to have a recordset that loads the values into the dropdown, then you would in your
| > SQL Select statement exclude the default value [objrs("TotalHrs")], in you example that would be
| > "4". Then your list would be 0,1,2,3,5,6, now this could lead to a problem if the user make a
| > selection of say "5" then changes their mind, they would not be able to put back the "4".
| >
| > --
| > ==============================================
| > Thomas A. Rowe
| > Microsoft MVP - FrontPage
| >
| > http://www.Ecom-Data.com
| > ==============================================
| >
| >
| > | > > Hi,
| > >
| > > That sort of works, but now I have the value in the list twice, so if the
| > > number in the db was 4, the drop-down list now is 4,0,1,2,3,4,5,6... - any
| > > way around this??
| > >
| > > Lisa
| > >
| > > "Stefan B Rusynko" wrote:
| > >
| > >> Open your db/rs and get the field - say TotalHrs
| > >>
| > >> Then Add it as your 1st field
| > >> <select size="1" name="Total_Hours">
| > >> <option value="<%=objrs("TotalHrs")%>"><%=objrs("TotalHrs")%></option>
| > >> <option>0</option>
| > >> ......
| > >>
| > >> See http://www.asp101.com/samples/db_edit.asp
| > >> --
| > >>
| > >> _____________________________________________
| > >> SBR @ ENJOY (-: [ Microsoft MVP - FrontPage ]
| > >> "Warning - Using the F1 Key will not break anything!" (-;
| > >> _____________________________________________
| > >>
| > >>
| > >> | > >> | Hi,
| > >> |
| > >> | I have an .asp page that loads a MS Access database from a form, one of the
| > >> | fields, Total_Hours is a drop-down box. Now I need an update page to allow
| > >> | the user to change the Total_Hours, so I need to set the drop-down value to
| > >> | the value stored in the database. How/where can I set this up so the field
| > >> | could be changed before saving back to the database?
| > >> |
| > >> | <select size="1" name="Total_Hours">
| > >> | <option>0</option>
| > >> | <option>1</option>
| > >> | <option>2</option>
| > >> | <option>3</option>
| > >> | <option>4</option>
| > >> | <option>5</option>
| > >> | <option>6</option>
| > >> | <option>7</option>
| > >> | <option>8</option>
| > >> | <option>9</option>
| > >> | <option>10</option>
| > >> | </select></tr>
| > >> |
| > >> | Lisa
| > >> |
| > >>
| > >>
| > >>
| >
| >
| >
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top