I am working on a database with survey question.
The form include main form with demographich info and a subform with survey questions.
My logic is : for all questions, the default answer is Yes, it can be changed to No or Null. However, if you change a question with No answer, you cannot go back to Yes or null. If you check a question with No answer, a form will pop up which allow you to add comments.
It works fine for a while, however, a big problem was found one day:
If the participant 1 check certain questions with NO, the rest of the participants cannot check No for the same question except for question 1. Sound weird!
the code for question subform:
Option Compare Database
Option Explicit
Private Sub cbQ1_AfterUpdate()
If [cbQ1] = "No" Then
[QuestionNumber] = 1
[cbQ1].Locked = True
DoCmd.OpenForm "frmNoResponse", , , "[ParticipantID] = Forms!Demo![ParticipantID]"
End If
End Sub
Private Sub cbQ1_DblClick(Cancel As Integer)
If [cbQ1] <> "No" Then
[cbQ1] = " "
End If
End Sub
Private Sub cbQ2_AfterUpdate()
If [cbQ2] = "No" Then
[QuestionNumber] = 2
[cbQ2].Locked = True
DoCmd.OpenForm "frmNoResponse", , , "[ParticipantID] = Forms!Demo![ParticipantID]"
End If
End Sub
Private Sub cbQ2_DblClick(Cancel As Integer)
If [cbQ2] <> "No" Then
[cbQ2] = " "
End If
End Sub
(same for the rest of the questions)
Private Sub Form_Current()
On Error GoTo Err_Form_Current
[QuestionNumber] = Null
If [ParticipantID] = Null Then
[cbQ1].Locked = False
[cbQ2].Locked = False
End If
Select Case [ParticipantID] > 0
Case [cbQ1] = "Yes" Or IsNull([cbQ1]) Or [cbQ1] = " "
[cbQ1].Locked = False
Case [cbQ1] = "No"
[cbQ1].Locked = True
Case [cbQ2] = "Yes" Or IsNull([cbQ2]) Or [cbQ2] = " "
[cbQ2].Locked = False
Case [cbQ2] = "No"
[cbQ2].Locked = True
(same for the other questions)
End Select
Exit_Form_Current:
Exit Sub
Err_Form_Current:
MsgBox Err.Description
Resume Exit_Form_Current
End Sub
Private Sub Form_Load()
Me.Repaint
End Sub
The form include main form with demographich info and a subform with survey questions.
My logic is : for all questions, the default answer is Yes, it can be changed to No or Null. However, if you change a question with No answer, you cannot go back to Yes or null. If you check a question with No answer, a form will pop up which allow you to add comments.
It works fine for a while, however, a big problem was found one day:
If the participant 1 check certain questions with NO, the rest of the participants cannot check No for the same question except for question 1. Sound weird!
the code for question subform:
Option Compare Database
Option Explicit
Private Sub cbQ1_AfterUpdate()
If [cbQ1] = "No" Then
[QuestionNumber] = 1
[cbQ1].Locked = True
DoCmd.OpenForm "frmNoResponse", , , "[ParticipantID] = Forms!Demo![ParticipantID]"
End If
End Sub
Private Sub cbQ1_DblClick(Cancel As Integer)
If [cbQ1] <> "No" Then
[cbQ1] = " "
End If
End Sub
Private Sub cbQ2_AfterUpdate()
If [cbQ2] = "No" Then
[QuestionNumber] = 2
[cbQ2].Locked = True
DoCmd.OpenForm "frmNoResponse", , , "[ParticipantID] = Forms!Demo![ParticipantID]"
End If
End Sub
Private Sub cbQ2_DblClick(Cancel As Integer)
If [cbQ2] <> "No" Then
[cbQ2] = " "
End If
End Sub
(same for the rest of the questions)
Private Sub Form_Current()
On Error GoTo Err_Form_Current
[QuestionNumber] = Null
If [ParticipantID] = Null Then
[cbQ1].Locked = False
[cbQ2].Locked = False
End If
Select Case [ParticipantID] > 0
Case [cbQ1] = "Yes" Or IsNull([cbQ1]) Or [cbQ1] = " "
[cbQ1].Locked = False
Case [cbQ1] = "No"
[cbQ1].Locked = True
Case [cbQ2] = "Yes" Or IsNull([cbQ2]) Or [cbQ2] = " "
[cbQ2].Locked = False
Case [cbQ2] = "No"
[cbQ2].Locked = True
(same for the other questions)
End Select
Exit_Form_Current:
Exit Sub
Err_Form_Current:
MsgBox Err.Description
Resume Exit_Form_Current
End Sub
Private Sub Form_Load()
Me.Repaint
End Sub