none
I ask a quesion concerning group radiobotton on MS ACCESS, but it seems the question was not well understood RRS feed

  • Question

  • Am designing a program that has to do with e-leaning, where a student will be provided with a question from 1 to 60 and he has only one choice, A or B, or C, to choose and after making his choices he will click on submit botton wich will send his record to the database. 

    Now my question is, I've created a group radiobotton A,B,C how can I send the information to the database?


    Tuesday, October 11, 2016 2:50 PM

Answers

  • First we need to consider the logical model.  Let's assume your database comprises the following tables:

    Students
    ….StudentID  (PK)
    ….FirstName
    ….LastName

    Questions
    …..QuestionID  (PK)
    …..Question
    …..QuestionIndex

    The last column is one of integer numbers which determine the order in which the questions will be presented to the student.

    Answers
    ….AnswerID  (PK)
    ….Answer
    ….QuestionID  (FK)
    ….IsCorrect
    ….AnswerIndex

    The IsCorrect column in the above is a Boolean data type (Yes/No) and indicates whether the answer is the correct one of the three possible answers per question. The AnswerIndex column is a column of integer numbers from 1 to 3 which determined the order in which the possible answers per question are presented to the student.

    Responses
    ….StudentID  (FK)
    ….QuestionID  (FK)
    ….AnswerID  (FK)

    This table models the many-to-many relationship type between Students and Answers.  Its primary key is a composite made up  of the StudentID and QuestionID  foreign key columns.

    In a form bound to the Responses table bind combo box controls to the StudentID and QuestionID columns.  The StudentID and QuestionID values can easily be inserted into rows in the table when a student's responses are first initiated, e.g. by their selecting their name in a combo box in an unbound opening form.  The bound column of the combo box would be a hidden StudentID column.  The code to do this would be:

    Dim strSQL As String

    strSQL = "INSERT INTO  Responses(StudentID,QuestionID) " & _
        "SELECT " & Me.cboStudent & ", QuestionID " & _
        "FROM Questions"

    CurrentDb.Execute strSQL, dbFailOnError

    Having inserted rows into Responses in this way a form bound to a query based on the table, ordering the query so as to present the  can then be opened filtered to the student, with:

    Dim strCriteria As String

    strCriteria = "StudentID = " & Me.cboStudent

    DoCmd.OpenForm "frmResonses", WhereCondition:=strCriteria
    DoCmd.Close acForm, Me.Name

    The frmResponses form will now list all the questions, ready for the student to select an answer to each.  An unbound option group could be used for each set of three questions, but it would require you to write code in its AfterUpdate event procedure to update the AnswerID column in the current row.  Far simpler would be a combo or list box bound to the AnswerID  column.  The combo or list box's RowSource property would be a query which returns those rows from Answers in which the QuestionID value is that of the current question, i.e.

    SELECT AnswerID, Answer FROM Answers WHERE QuestionID = Form!cboQuestion ORDER BY AnswerIndex;

    The cboQuestion control is the combo box bound to the QuestionID column.  In its AfterUpdate event procedure the combo box bound to the AnswerID column would be requeried, e.g.

    Me.cboAnswer = Null
    Me.cboAnswer.Requery

    It should also be requeried in the form's Current event procedure with:

    Me.cboAnswer.Requery

    If you really want to use an option group, then the values of the option buttons should be 1, 2 and 3, corresponding to the AnswerIndex values for each question.  You can then assign a value to the AnswerID column in the current row with code in the option group's AfterUpdate event procedure:

    Dim strCriteria As String

    strCriteria = "QuestionID = " & Me.cboQuestion & " And AnswerIndex = " & Me.optAnsers

    Me.AnswerID = DLookup("AnswerID", "Answers", strCriteria)

    where cboQuestion  is the control bound to QuestionID, and optAnsers is the unbound option group.

    The option group's current selection should be cleared in the form's Current event procedure with:

    Me.optAnsers = Null


    Ken Sheridan, Stafford, England

    Tuesday, October 11, 2016 5:04 PM

All replies

  • Hi,

    Assuming you created the buttons on an Access form, then binding the controls to the table should automatically send the choices to the database.

    Hope it helps...

    Tuesday, October 11, 2016 4:10 PM
  • First we need to consider the logical model.  Let's assume your database comprises the following tables:

    Students
    ….StudentID  (PK)
    ….FirstName
    ….LastName

    Questions
    …..QuestionID  (PK)
    …..Question
    …..QuestionIndex

    The last column is one of integer numbers which determine the order in which the questions will be presented to the student.

    Answers
    ….AnswerID  (PK)
    ….Answer
    ….QuestionID  (FK)
    ….IsCorrect
    ….AnswerIndex

    The IsCorrect column in the above is a Boolean data type (Yes/No) and indicates whether the answer is the correct one of the three possible answers per question. The AnswerIndex column is a column of integer numbers from 1 to 3 which determined the order in which the possible answers per question are presented to the student.

    Responses
    ….StudentID  (FK)
    ….QuestionID  (FK)
    ….AnswerID  (FK)

    This table models the many-to-many relationship type between Students and Answers.  Its primary key is a composite made up  of the StudentID and QuestionID  foreign key columns.

    In a form bound to the Responses table bind combo box controls to the StudentID and QuestionID columns.  The StudentID and QuestionID values can easily be inserted into rows in the table when a student's responses are first initiated, e.g. by their selecting their name in a combo box in an unbound opening form.  The bound column of the combo box would be a hidden StudentID column.  The code to do this would be:

    Dim strSQL As String

    strSQL = "INSERT INTO  Responses(StudentID,QuestionID) " & _
        "SELECT " & Me.cboStudent & ", QuestionID " & _
        "FROM Questions"

    CurrentDb.Execute strSQL, dbFailOnError

    Having inserted rows into Responses in this way a form bound to a query based on the table, ordering the query so as to present the  can then be opened filtered to the student, with:

    Dim strCriteria As String

    strCriteria = "StudentID = " & Me.cboStudent

    DoCmd.OpenForm "frmResonses", WhereCondition:=strCriteria
    DoCmd.Close acForm, Me.Name

    The frmResponses form will now list all the questions, ready for the student to select an answer to each.  An unbound option group could be used for each set of three questions, but it would require you to write code in its AfterUpdate event procedure to update the AnswerID column in the current row.  Far simpler would be a combo or list box bound to the AnswerID  column.  The combo or list box's RowSource property would be a query which returns those rows from Answers in which the QuestionID value is that of the current question, i.e.

    SELECT AnswerID, Answer FROM Answers WHERE QuestionID = Form!cboQuestion ORDER BY AnswerIndex;

    The cboQuestion control is the combo box bound to the QuestionID column.  In its AfterUpdate event procedure the combo box bound to the AnswerID column would be requeried, e.g.

    Me.cboAnswer = Null
    Me.cboAnswer.Requery

    It should also be requeried in the form's Current event procedure with:

    Me.cboAnswer.Requery

    If you really want to use an option group, then the values of the option buttons should be 1, 2 and 3, corresponding to the AnswerIndex values for each question.  You can then assign a value to the AnswerID column in the current row with code in the option group's AfterUpdate event procedure:

    Dim strCriteria As String

    strCriteria = "QuestionID = " & Me.cboQuestion & " And AnswerIndex = " & Me.optAnsers

    Me.AnswerID = DLookup("AnswerID", "Answers", strCriteria)

    where cboQuestion  is the control bound to QuestionID, and optAnsers is the unbound option group.

    The option group's current selection should be cleared in the form's Current event procedure with:

    Me.optAnsers = Null


    Ken Sheridan, Stafford, England

    Tuesday, October 11, 2016 5:04 PM
  • OK mister ken sheridan

    Let me try it and see.

    Wednesday, October 12, 2016 12:21 PM
  • Hi MC COOLEST,

    Have you resolved your issue? If you have any issue, please feel free post them on MSDN forum.

    Thanks for your understanding.

    Tuesday, October 18, 2016 7:56 AM