473,499 Members | 1,672 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I display a selected Recordset from a database into a combobox?

6 New Member
Hi there,

I'm trying to create an Update page in ASP so that I can update a student's info. The problem I'm having is displaying the current teacher the student currently has in the combobox. I'd like to have the current teacher already selected in the combobox so that I don't accidentally select the same teacher. (E.g. If a Student changes his/her teacher from Mr. Smith over to Mr. Jones, the in the Update page, Mr. Smith is already selected in the combobox, and I can select Mr. Jones within the same combobox)

Here are my tables and fields that I have;

tblTeachers

fldTeacherID
1
2
3

fldTeacherName
Mrs. Avery
Mr. Jones
Mr. Smith

tblStudents

fldStudentID
1
2
3

fldTeacherID
3 (Student 1 has Mr. Smith)
2 (Student 2 has Mr. Jones)
1 (Student 3 has Mrs. Avery)


Could someone help out please?

Thx!

Genki Dave
Feb 24 '10 #1
6 1991
GazMathias
228 Recognized Expert New Member
You simply need to compare the teacher ID to the one on the student record and mark it selected if it matches:

Not sure if you are using code to populate the combo boxes, but this approach usually works for me. I've not used your fieldnames so you will need to change them.

Expand|Select|Wrap|Line Numbers
  1. <select id="cboteacher">
  2. <%
  3. Do While Not teacher.EOF ' where teacher is an open recordset
  4.   If student("teacherID") = teacher("teacherID") then selected = " Selected " Else Selected = " "
  5.   response.Write "<option" & selected & "value =" & teacher.ID & ">" & teacher("name") & "</option>"
  6.  teacher.MoveNext
  7. Loop
  8. %>
  9. </select>
  10.  
Obviously the student recordset needs to be open before the teacher one.

Gaz
Feb 25 '10 #2
genkidave
6 New Member
Hmm, I tried it, but I kept on getting errors. Thanks though. It said that teacher and student were "Undefined"???

Dave
Feb 26 '10 #3
GazMathias
228 Recognized Expert New Member
Hi,

It is not working for you because I did not use your fieldnames in the code. You need to change them.

I illustrated it with fictional record sets named "teacher" and "student" and assumed that the field being compared was called "teacherID".

Simply change the record sets and field names to the real ones, or post your code here.

Gaz
Feb 26 '10 #4
genkidave
6 New Member
I understand that part and used my actual field names "tblTeachers" "fldTeacherName", etc... I still couldn't get it to work.

I'll figure it out somehow...

Dave
Feb 26 '10 #5
GazMathias
228 Recognized Expert New Member
Hi,

If you are still having problems, post the code that directly pertains to this problem and I'll have a look, including all code that relates to the relevant record sets (opening moving through and closing). Remember to use code tags too ;)

Gaz.
Feb 26 '10 #6
genkidave
6 New Member
Actually, I figured it out and slapped my head. I was using the incorrect recordset name. The recordset "rsTeacher" should have been, "rsTeacherUpdate". all is well now, LoL!

Thanks for your patience and help!!!

Dave
Feb 26 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
4772
by: Corepaul | last post by:
As input is typed into a text box, I would like to search a recordset for the first record that matches what has been typed so far. I would like to update the text box to display the letters typed...
17
2051
by: perryche | last post by:
I have 5records, e.g. Rc1, Rc2, Rc3..., when user open up a form, I want it to open to a particular record (say Rc3) then when user chooses the Record Selector , it will go to Rc2 and , it will go...
3
4011
by: google | last post by:
This is something I've done plenty of times in '97, but I can't seem to get it to work correctly in Access 2003. Say, for example, I have a form with an unbound combobox, the data source is a...
4
6653
by: Michael Turner | last post by:
Hi I am having a problem with a combobox the values are generated from a recordset, I need to beable to change the selected item to the value specified in a configuration file, I have stored the...
5
2128
by: bryan.com | last post by:
There must be a way. I'm making a selection from a drop-down list that had an ID number as the value and displays a text field. After submitting the data to the database I am sending an email and...
1
1736
by: mramsay | last post by:
Hi there, I have a dynamic hyperlink Baseball. When the user select the hyperlink they are redirected to another page. After that I want to display information on the page from my linkstbl. ...
2
3075
by: giandeo | last post by:
Hello all, It's almost a couple of weeks since i am struggling to get this code work. Unfortunately, i am stuck. There seems to be no hope... Please Help....... I am working with an asp page...
7
4859
by: creative1 | last post by:
hi, I have a simple query. I have a dynamic combobox when I select one value fromt he combobox; on click a function is called that display the value of the combobox(i.e not same as text list of...
2
3664
by: kurtzky | last post by:
i created a form that should function as follows: i will enter a number in a textbox..then it should query from the database all the records which has that number..these records will have a...
8
1637
by: ZaphodBBB | last post by:
Hi I have a form frmAdd_Equipment. It has a number of combo boxes on it, cboModel, cboSupplier, cboManufacturer, cboEquipment_Type etc. Bcause therer is no existing data to go off I put an ADD...
0
7131
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7220
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7388
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4600
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3099
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3091
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.