Hello,
I have a form which has several comboboxes with the dropdown options of "N/A, 4,3,2,1". I have a text box (txtScore) which should populate when the user presses the btnCalculate. I am getting a Type Mismatch error however and I cannot figure out what the issue is.
In the table that the form is connected to the fields with the comboboxes are formatted as Short Text but I have also tried Number. The txtScore field is formatted as Number.
The code I am using I currently use in an Excel Userform and it works there. So maybe everything does not transfer over exactly in Access? This is the piece that highlights with the Type Mismatch error: control_value = control_value + CInt(target_control.Value)
Any help would be greatly appreciated!
Code:
Private Sub btnCalculate_Click()
Dim target_control As Control
Dim control_value As Integer
Dim control_count As Integer
control_value = 0
control_count = 0
For Each target_control In Me.Controls
If TypeName(target_control) = "ComboBox" Then
If Not target_control.Value = "N/A" Then
control_value = control_value + CInt(target_control.Value)
control_count = control_count + 1
End If
End If
Next
txtPotential = control_count * 4
txtScore = Format((control_value / txtPotential), "Percent")
For Each c In Me.Controls
If TypeName(target_control) = "ComboBox" Then
If target_control.Value = "" Then na = MsgBox("All fields must be selected. Please choose 1-4 or N/A before continuing.", vbOKOnly, "Quarterly Audits")
End If
Next
End Sub