'Open ADO connection
Dim SRT_DBcn As New ADODB.Connection
cnString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & App.Path & "\SRT_DB.mdb;Persist Security Info=False"
SRT_DBcn.Open cnString
Dim cmd As New ADODB.Command
Dim rsSurvey As New ADODB.Recordset
Dim SurveyRS As String
Let SurveyRS = NewSurvey & "_QstData"
'Open Survey Question data table
rsSurvey.Open SurveyRS, SRT_DBcn, adOpenKeyset, adLockOptimistic
DoEvents
With rsSurvey
.MoveFirst
Do Until rsSurvey.EOF
'Look at Scale_Label (text field), if "--" then it does not require a bar, if has text other than -- it requires a bar
If (rsSurvey!Scale_Label = "--") Then
rsSurvey.MoveNext
'If Scale_Label includes text other than -- it requires a bar
ElseIf (rsSurvey!Scale_Label <> "--") Then
'Look at Continuous_Recode, if "NO" then bar_value needs to be calculated, otherwise the calculation was done earlier
If (rsSurvey!Continuous_Recode = "NO") Then
'if Response_1 is "--" and Response_2 has text then the calculation will be based on the value in "2" (text field)
If (rsSurvey!Response_1 = "--") And (rsSurvey!Response_2 <> "--") Then
cmd.CommandText = "UPDATE " & NewSurvey & "_QstData SET " & NewSurvey & "_QstData.Bar_Value = ROUND(val(" _
& NewSurvey & "_QstData.2) - " & NewSurvey & "_QstData.Min_Val) / (" & NewSurvey & "_QstData.Max_Val - " _
& NewSurvey & "_QstData.Min_Val)"
cmd.CommandType = adCmdText
SRT_DBcn.Execute cmd.CommandText
'if Response_2 is "--" and Response_1 has text then the calculation will be based on the value in "1" (text field)
ElseIf (rsSurvey!Response_2 = "--") And (rsSurvey!Response_1 <> "--") Then
cmd.CommandText = "UPDATE " & NewSurvey & "_QstData SET " & NewSurvey & "_QstData.Bar_Value = ROUND(val(" _
& NewSurvey & "_QstData.1) - " & NewSurvey & "_QstData.Min_Val) / (" & NewSurvey & "_QstData.Max_Val - " _
& NewSurvey & "_QstData.Min_Val)"
cmd.CommandType = adCmdText
SRT_DBcn.Execute cmd.CommandText
'if Response_2 is "--" and Response_1 is "--" then the calculation will be based on the value in PR (text field)
ElseIf (rsSurvey!Response_1 = "--") And (rsSurvey!Response_2 = "--") Then
cmd.CommandText = "UPDATE " & NewSurvey & "_QstData SET " & NewSurvey & "_QstData.Bar_Value = ROUND(val(" & NewSurvey & "_QstData.PR) - " _
& NewSurvey & "_QstData.Min_Val) / (" & NewSurvey & "_QstData.Max_Val - " & NewSurvey & "_QstData.Min_Val)"
cmd.CommandType = adCmdText
SRT_DBcn.Execute cmd.CommandText
End If 'end looking at 1, 2, and PR
End If 'end looking for all with Recode = "NO"
End If ' end if for checking scale_label and BarValue for missing values - items without CR
.MoveNext 'move to next record
Loop
End With