alliandrina
Registered User.
- Local time
- Today, 15:00
- Joined
- Mar 9, 2011
- Messages
- 13
I have a db that I wasn't the one who wrote. I'm actually pretty much a noob at this. Up until recently one of the forms had a bound list box. When I changed it to an unbound list box, the selections stopped being recorded. I know its possible to record those selections still because there is another form with an unbound list box on it.
The code for that vba is;
Of course it isn't working. And I was hoping that someone could give me some advice on how to get it to work. Thanks in advance.
The code for that vba is;
Code:
Option Compare Database
Option Explicit
Private Sub cmdCancelEval_Click()
If MsgBox("Are you sure you want to cancel? You will have to completely " & _
"re-enter ALL responses if you Cancel.", vbYesNo, "Confirm Cancellation...") = _
vbYes Then
booCancelEval = True
DoCmd.Close
End If
End Sub
Private Sub Form_Current()
Me.lstChoices.Requery
End Sub
Private Sub Form_Open(Cancel As Integer)
Me.lstChoices.Requery
End Sub
Private Sub cmdNextQuestion_Click()
On Error GoTo Err_cmdNextQuestion_Click
If SelectionMade() Then
If CheckForOther() Then
If Nz(Len(Me.txtOther), 0) = 0 Then
MsgBox "If you select Other, you must make an entry for this category.", _
vbOKOnly , "No 'Other' Entry Made..."
Me.txtOther.SetFocus
Exit Sub
Else
Dim strSQL As String
strSQL = "INSERT INTO tblTEMPSurveyLongResponse ( SurveyRespID, LongResponse ) "
strSQL = strSQL & "SELECT tblTEMPSurveyResponses.SurveyRespID, '"
strSQL = strSQL & Me.txtOther & "' AS Expr1 FROM tblTEMPSurveyResponses "
strSQL = strSQL & "WHERE (((tblTEMPSurveyResponses.SubjChoiceID)=56));"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
Me.txtOther = Null
Me.txtOther.Visible = False
End If
End If
DoCmd.GoToRecord , , acNext
Dim i As Integer
For i = 0 To Me.lstChoices.ListCount
Me.lstChoices.Selected(i) = False
Next i
Me.txtOther = Null
Else
MsgBox "Each question must be completed first.", vbOKOnly, "Please Respond..."
End If
Exit_cmdNextQuestion_Click:
Exit Sub
Err_cmdNextQuestion_Click:
If Err.Number = 2105 Then
If MsgBox("Last question completed. Ready to move to the next section?", vbYesNo, _
"Section Complete...") = vbYes Then
DoCmd.Close
Else
MsgBox "Click -> again to move to next section.", vbOKOnly, "Continue When Ready..."
End If
Else
MsgBox Err.Descrption
End If
Resume Exit_cmdNextQuestion_Click
End Sub
Private Function SelectionMade() As Boolean
Dim X As Integer
For X = 0 To Me.lstChoices.ListCount
If Me.lstChoices.Selected(X) = True Then
SelectionMade = True
Exit Function
End If
Next X
SelectionMade = False
End Function
Private Sub lstChoices_Click()
Call AddRemoveChoices
Me.txtOther.Visible = CheckForOther()
If CheckForOther() Then Me.txtOther.SetFocus
End Sub
Private Sub AddRemoveChoices()
Dim X As Integer
Dim strSQL As String
Dim strwhere As String
Dim strIDs As String
strSQL = "DELETE tblTEMPSurveyResponses.*, tblTEMPSurveyResponses.SurveySubjID, "
strSQL = strSQL & "tblTEMPSurveyResponses.SubjChoiceID FROM tblTEMPSurveyResponses "
strwhere = "WHERE tblTEMPSurveyResponses.SurveySubjID=" & Me.SurveySubjID
strwhere = strwhere & " AND tblTEMPSurveyResponses.SubjChoiceID In ("
For X = 0 To Me.lstChoices.ListCount
If Me.lstChoices.Selected(X) = False And Nz(Len(Me.lstChoices.Column(0, X)), 0) > 0 Then
strIDs = strIDs & Me.lstChoices.Column(0, X) & ","
End If
Next X
If Nz(Len(strIDs), 0) > 0 Then
strIDs = Left(strIDs, Len(strIDs) - 1)
End If
If Nz(Len(strIDs), 0) > 0 Then
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL & strwhere & strIDs & ");"
DoCmd.SetWarnings True
End If
strSQL = "INSERT INTO tblTEMPSurveyResponses ( ClassID, SurveySubjID, SurveyID, ParticipantTypeID, StudentID, "
strSQL = strSQL & "SchooliD, SubjChoiceID ) SELECT " & Forms!TeacherSurvey.cboClass & " AS "
strSQL = strSQL & "Expr2, " & Me.SurveySubjID & " AS Expr1, " & Forms!TeacherSurvey.cboSurveys & " AS "
strSQL = strSQL & "Expr3, " & Forms!TeacherSurvey.cboPt & " AS Expr4, " & Forms!TeacherSurvey.cboStudent & " AS "
strSQL = strSQL & "Expr5, " & Forms!TeacherSurvey.cboSchool & " As Expr6, SubjectChoiceID FROM tblSubjectChoices "
strwhere = "WHERE tblSubjectChoices.SubjectChoiceID In ("
strIDs = ""
For X = 0 To Me.lstChoices.ListCount
If Me.lstChoices.Selected(X) = True And Nz(Len(Me.lstChoices.Column(0, X)), 0) > 0 Then
strIDs = strIDs & Me.lstChoices.Column(0, X) & ","
End If
Next X
If Nz(Len(strIDs), 0) > 0 Then
strIDs = Left(strIDs, Len(strIDs) - 1)
End If
If Nz(Len(strIDs), 0) > 0 Then
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL & strwhere & strIDs & ");"
DoCmd.SetWarnings True
End If
End Sub
Private Function CheckForOther() As Boolean
Dim X As Integer
For X = 0 To Me.lstChoices.ListCount
If Left(Me.lstChoices.Column(1, X), 7) = "Other (" And Me.lstChoices.Selected(X) Then
CheckForOther = True
Exit Function
End If
Next X
CheckForOther = False
End Function
I think its the part in blue that causes it to be read and stored, but I could be wrong. i have tried to change the other list box 's vba using this as a basis and here it is:
Option Compare Database
Option Explicit
Private Sub cmdCancelEval_Click()
If MsgBox("Are you sure you want to cancel? You will have to completely " & _
"re-enter ALL responses if you Cancel.", vbYesNo, "Confirm Cancellation...") = _
vbYes Then
booCancelEval = True
DoCmd.Close
End If
End Sub
Private Sub Form_Current()
Me.SubjChoiceID.Requery
End Sub
Private Sub Form_Open(Cancel As Integer)
Me.SubjChoiceID.Requery
End Sub
Private Sub cmdPreviousQuestion_Click()
On Error GoTo Err_cmdPreviousQuestion_Click
DoCmd.GoToRecord , , acPrevious
Exit_cmdPreviousQuestion_Click:
Exit Sub
Err_cmdPreviousQuestion_Click:
If Err.Number = 2105 Then
MsgBox "First question. Can't move to the previous one.", vbOKOnly, _
"Beginning of survey..."
Else
MsgBox Err.Description
End If
Resume Exit_cmdPreviousQuestion_Click
End Sub
Private Sub cmdNextQuestion_Click()
On Error GoTo Err_cmdNextQuestion_Click
If SelectionMade() Then
DoCmd.GoToRecord , , acNext
Dim i As Integer
For i = 0 To Me.SubjChoiceID
Me.SubjChoiceID.Selected(i) = True
Next i
Else
MsgBox "Each question must be completed first.", vbOKOnly, "Please Respond..."
End If
Exit_cmdNextQuestion_Click:
Exit Sub
Err_cmdNextQuestion_Click:
If Err.Number = 2105 Then
If MsgBox("Last question completed. Ready to finish the survey?", vbYesNo, _
"Survey Complete...") = vbYes Then
DoCmd.Close
MsgBox "Thank you for your feedback!", vbOKOnly, "Thank You!!"
Else
MsgBox "Click -> again to move to finish.", vbOKOnly, "Finish When Ready..."
End If
Else
MsgBox Err.Description
End If
Resume Exit_cmdNextQuestion_Click
End Sub
Private Function SelectionMade() As Boolean
Dim X As Integer
For X = 0 To Me.SubjChoiceID
If Me.SubjChoiceID.Selected(X) = True Then
SelectionMade = True
Exit Function
End If
Next X
SelectionMade = False
End Function
Private Sub SubjChoiceID_Click()
Call AddRemoveChoices
If SelectionMade() Then Me.SubjChoiceID.SetFocus
End Sub
Private Sub AddRemoveChoices()
Dim X As Integer
Dim strSQL As String
Dim strwhere As String
Dim strIDs As String
strSQL = "INSERT INTO tblTEMPSurveyResponses ( ClassID, SurveySubjID, SurveyID, ParticipantTypeID, StudentID, "
strSQL = strSQL & "SchooliD, SubjChoiceID ) SELECT " & Forms!TeacherSurvey.cboClass & " AS "
strSQL = strSQL & "Expr2, " & Me.SurveySubjID & " AS Expr1, " & Forms!TeacherSurvey.cboSurveys & " AS "
strSQL = strSQL & "Expr3, " & Forms!TeacherSurvey.cboPt & " AS Expr4, " & Forms!TeacherSurvey.cboStudent & " AS "
strSQL = strSQL & "Expr5, " & Forms!TeacherSurvey.cboSchool & " As Expr6, SubjectChoiceID FROM tblSubjectChoices "
strwhere = "WHERE tblSubjectChoices.SubjectChoiceID In ("
strIDs = ""
For X = 0 To Me.SubjChoiceID
If Me.SubjChoiceID.Selected(X) = True And Nz(Len(Me.SubjChoiceID.Column(0, X)), 0) > 0 Then
strIDs = strIDs & Me.SubjChoiceID(0, X) & ","
End If
Next X
If Nz(Len(strIDs), 0) > 0 Then
strIDs = Left(strIDs, Len(strIDs) - 1)
End If
If Nz(Len(strIDs), 0) > 0 Then
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL & strwhere & strIDs & ");"
DoCmd.SetWarnings True
End If
End Sub
Of course it isn't working. And I was hoping that someone could give me some advice on how to get it to work. Thanks in advance.
Last edited by a moderator: