473,626 Members | 3,320 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 2002
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 "tblTeacher s" "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, "rsTeacherUpdat e". 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
4796
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 by the user in the normal font and any additional characters in the first matching record displayed as highlighted text. This matches the action of the MS Access help index. I can use the OnKeyPress event to trigger a new check for the "best"...
17
2064
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 to Rc4. If I use Sort in the query, it is sorted alphabetically; if I do not sort, whatever is the latest record will be on top. Any help/insight will be appreciated. Perry
3
4021
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 table of customers, first column is the key field, which is hidden with a 0" width, and the second column is the customer name. The SQL is a union query that also inserts Null in the first column, and "All" in the second column. That combobox gets...
4
6681
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 value as a varible. I am using the code below but it isn't working any ideas am I using the right method. combobox1.selecteditem = getcolvalue(0) Any help appreciated.
5
2133
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 would like to include the value displayed in the DD box, not the hidden value. How so I reference that displayed value? <select name="select"> <option value="1">Blue</option> <option value="2">Red</option> <option value="3">Green</option>
1
1744
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. The information I want to display is Baseball and some text I have entered in the database. I'm having a problem displaying the two fields for Baseball. The two field names are linkdescription and text. How do I get my sql query to pull out the...
2
3085
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 that dynamically pulls info from my database to populate a drop down menu. Upon an onChange event, I wish to display the fields related to that pull down menu WITHOUT SUBMITTING THE PAGE. The Senario: Database name: sp.mdb
7
4870
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 combobox) in textbox on the form. I want to display the selected entry(not the value) of the combobox in another text box. How I can do that this is what I already have function getvalue(form) { ...
2
3677
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 different item no in it..then, these records will be saved in a temporary datatable (which i made in a separate class, the name is WBASKET)...The item nos of these records will be displayed in a combobox, say item1, item2, etc.. then,i have a datagrid...
8
1648
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 NEW cmdButton next to each of the ComboBoxes so if the item does not exist then the user can add a new Model, Supplier etc. The various ComboBoxes all load from Queries when the Form Loads. What I'd like to do, is to make it so that should the...
0
8266
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8705
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8638
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8365
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8505
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6125
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4092
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1511
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.