I am new on this forum and to Access VBA. I would appreciate assistance in fixing this a bug that reads "Run time Error "the value you entered isn't valid for this field" (80020009) ".
I am writing an online exam program code that retrieves questions and options from a table and this information is displayed in text boxes on a form from which the user can select an option. I have used a recordset object for this purpose which works perfectly. I also have an unbound textbox on the form that displays the option selected by the user and want the value in the textbox attached to each record in the recordset. i was able to do this successfully but the challenge is that anytime i navigate to the beginning of file using a "previous" button on the form, I get the Run time Error "the value you entered isn't valid for this field" (80020009). i have a conditional statement that checks for BOF, but the error still persists. Below is the code i have written and the line generating the record is indicated in bold print. Any help in fixing this will be highly appreciated.
Private Sub Form_Load()
Set rst = CurrentDb.OpenRecordset("select id, question, A, B, C, D, E, SECT, response FROM TABLE2 WHERE TAG = TRUE ", dbOpenDynaset)
Me.Text13 = rst!question
Me.Text20 = rst!A
Me.Text22 = rst!B
Me.Text26 = rst!C
Me.Text28 = rst!D
Me.Text30 = rst!E
End Sub
Private Sub Command37_Click()
If Not rst.EOF Then
rst.Edit
rst!response = Me.Text38
rst.Update
rst.MoveNext
refreshpg
Command15.BackColor = vbWhite
Command16.BackColor = vbWhite
Command17.BackColor = vbWhite
Command18.BackColor = vbWhite
Command19.BackColor = vbWhite
Me.Text38 = ""
Command37.Enabled = True
Else
Command37.Enabled = False
End If
End Sub
Private Sub Command36_Click()
If Not rst.BOF Then
Command15.BackColor = vbWhite
Command16.BackColor = vbWhite
Command17.BackColor = vbWhite
Command18.BackColor = vbWhite
Command19.BackColor = vbWhite
Me.Text38 = ""
rst.MovePrevious
Me.Text38 = rst!response
chosenoption
refreshpg
Else
Command36.Enabled = False
End If
End Sub
Private Sub refreshpg()
If Not rst.BOF And Not rst.EOF Then
Me.Text13 = rst!question
Me.Text20 = rst!A
Me.Text22 = rst!B
Me.Text26 = rst!C
Me.Text28 = rst!D
Me.Text30 = rst!E
Me.Text40 = rst!id
End If
End Sub
Private Sub chosenoption()
If Me.Text38 = "A" Then
Me.Command15.BackColor = 1000
End If
If Me.Text38 = "B" Then
Me.Command16.BackColor = 1000
End If
If Me.Text38 = "C" Then
Me.Command17.BackColor = 1000
End If
If Me.Text38 = "D" Then
Me.Command18.BackColor = 1000
End If
If Me.Text38 = "E" Then
Me.Command19.BackColor = 1000
End If
End Sub