Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    RedGoneWILD is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    105

    need help - combobox controls table?

    I really need help with this

    I have a detail form linked to a students table that displays all kinds of information about the student. for any info thats in related tables, i used a subform so that its easy to add info and have those tables updated automatically.

    here's my problem.



    each student can have one or two advisors. i have two comboboxes on the student detail form that are automatically filled with the names of all possible advisors. The default value for each combobox is set to whoever their advisor(s) are. So if the student only has one advisor, it is set to combobox 1, and the other one remains blank. But if that student gets a second advisor, or changes an advisor, whatever, then i can select the advisor from the combobox.

    the question is how do i get the value of the combobox to update the table? since the student advisors are in a seperate table, the comboboxes are not bound like the other boxes on the form.

    if a student has one advisor, and i change that combobox, i want it to change the related record. or if the student adds an advisor, i want to create a new record.

    thanks in advance for any ideas or suggestions

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    in the data page of property of combo box, the first line is "control source", select the fieldname of the table which link to your form. when thing in combo box changes, the table will be updated.

  3. #3
    RedGoneWILD is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    105
    all it's giving me is a list of fields in the students table, which is the same table that the form is linked to.

    i have an advisor table which has an "AdvisorID" field, I have a student table which has a "StudentID" field...and then i have a table that links the two that's called tblStudentAdvisors which has only two fields, the AdvisorID & the StudentID.

    I basically need the combobox to update or add a record to tblStudentAdvisors even though the form itself is linked to tblStudents

  4. #4
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    just select the field in student table, that is where want to save the change, right?
    item shows in the combo box is from advisor table, but save to student table when it changes.

  5. #5
    RedGoneWILD is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    105
    no, the table that needs updated is tblStudentAdvisors

  6. #6
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    Oops...
    you need VBA code to perform this update. write some code in combo box change event to update tblStudentAdvisors

  7. #7
    RedGoneWILD is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    105
    yeah, thats what im trying to do...except i dont know the vba code to write...i was hoping you could help me with that...lol

  8. #8
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    How is you tblStudentAdvisors like?
    is it like: studentID, advisor1,advisor2,advisor3..., or
    studentID, advisorID ?

    please provide more detail of the fields of you tables.

  9. #9
    RedGoneWILD is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    105
    tblStudentAdvisors has just two fields..."StudentID" & "AdvisorID"

    a student can have up to two advisors, or two records in this table ...an advisor can have unlimited students

    The "StudentID" is the primary key for tblStudents and "AdvisorID" is the primary key of tblAdvisors

    furthermore, if it helps any...here is the code that i have so far that populates the two comboboxes with the current advisors for each student

    Code:
    'clear textboxes
        Me.cboAdvisor1.Value = ""
        Me.cboAdvisor2.Value = ""
        
        'declare variables
        Dim advisor1 As String
        Dim advisor2 As String
        Dim strSQL As String
        Dim rst As Recordset
        strSQL = "SELECT tblStudentAdvisors.*, tblFaculty.firstName, tblFaculty.LastName, tblFaculty.OfficePhone, tblFaculty.OfficeEmail, tblStudentAdvisors.studentID " & _
                 "FROM tblFaculty INNER JOIN tblStudentAdvisors ON tblFaculty.FacultyID = tblStudentAdvisors.FacultyID " & _
                 "WHERE tblStudentAdvisors.studentID = " & ID & ";"
        advisor1 = ""
        advisor2 = ""
        
        'display the results
        Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)
        If rst.RecordCount > 0 Then
            rst.MoveFirst
            Do While Not rst.EOF
                If IsNull(advisor1) Or advisor1 = "" Then
                    advisor1 = rst("lastName") & ", " & rst("firstName")
                Else
                    advisor2 = rst("lastName") & ", " & rst("firstName")
                End If
                rst.MoveNext
            Loop
            Me.cboAdvisor1.Value = advisor1
            Me.cboAdvisor2.Value = advisor2
        End If
        
        'Close and empty recordset
        rst.Close
        Set rst = Nothing

  10. #10
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    If one student have at most 2 advisor, I suggest you change the tblStudentAdvisors to have: studentID, advisor1, advisor2

    in your current table, if a student has 2 advisor and need to change one, how can we identify which to change?

    (I am leaving at 5:00 o'clock, may come back tomorrow)

  11. #11
    RedGoneWILD is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    105
    the problem with doing that is it violates normalization rules

    if i were to put an advisor1 and advisor2 field, then which one gets linked to the advisors table?

    the way i think this is done is that an after update event is triggered when the combobox is changed...i want that event to contain code that either replaces the current record with a new advisor, or adds a new advisor record to the table

    i just don't know what the correct SQL statement or VBA code would be

  12. #12
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    if i were to put an advisor1 and advisor2 field, then which one gets linked to the advisors table?
    My question is just on the contrary, you metioned you have 2 box in your form to show 2 advisors of the student, how do you put 2 advisors in each box if they are in 2 records? I believe your form is a single form.

  13. #13
    RedGoneWILD is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    105
    the two combo boxes are populated with a loop...the code i have to do that is posted above

  14. #14
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    I could not find the old value of advisor which I need it to decide which advisor is to be updated.

  15. #15
    RedGoneWILD is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    105
    i really need help with this....can anybody explain this to me?

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Tab Controls
    By karlhardeman in forum Forms
    Replies: 10
    Last Post: 08-25-2010, 07:01 AM
  2. Replies: 0
    Last Post: 08-24-2010, 06:38 PM
  3. Combobox and table interference
    By t_dot in forum Access
    Replies: 2
    Last Post: 08-12-2010, 07:04 AM
  4. Replies: 0
    Last Post: 12-16-2009, 01:14 PM
  5. Link ComboBox to field in a table
    By DrDebate in forum Forms
    Replies: 0
    Last Post: 04-27-2007, 08:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums