I am developing a test/survey app. The questions are a randomized subset of questions. Each question in the test needs to be answered. I track the number of questions in the test are left blank then will represent the questions at the end so the user can try again. The issue is when I try to go back to the question I get the following error:
Error 2046: The command or action 'GoToRecord' isn't available now.
the following is the code be used the issue occurs in the following seqment:
If lngSkip > 0 Then
Find_SkipRecord
boolRedisplay = True
MsgBox " lngTestRcd = " & lngTestRcd
Dim tmpr As Long
tmpr = 3
DoCmd.GoToRecord , "frmTest", Record:=tmpr
Not sure what is causing the error. The tmpr variable is being used as a test for the code. I added a line
DoCmd.GoToRecord , Record:=acFirst
just after the "if" statement with no issues.
Any suggestions would be appreciated.
Rof
==============complete routine===========================================
Private Sub Cmd_Submit_Click()
Dim dbs As Database
Dim ctl As Control
Dim tmpName As String
Dim tmpAns As Long
Dim boolAns As Boolean
On Error GoTo ErrorHandler
Set dbs = CurrentDb()
' Determine which option is selected
For Each ctl In Me.Controls
If ctl.ControlType = acCheckBox Then
tmpName = ctl.Name
If (Me.Controls(tmpName)) Then
tmpAns = CLng(Mid(tmpName, 7))
End If
End If
Next ctl
'Compare answer to correct answer
If (tmpAns = lngCorrectAns) Then
MsgBox "Correct"
boolAns = True
Else
Me.Controls("Option" & Trim(Str(lngCorrectAns))).SetFocus
MsgBox "That is incorrect. The answer is: " & vbCrLf _
& Me.Controls("Option" & Trim(Str(lngCorrectAns))).Text
boolAns = False
End If
If Not boolRedisplay Then
' Write data to complete registration
dbs.Execute "INSERT INTO tblTestHistory (lngEmployeeID, lngQClassID, ID_Question, lngCorrectAns, lngUserAns, boolCorrect, strTestDate, lngSession) " _
& "VALUES (" & ID.Value & ", " & Class.Value & ", " & Question.Value & ", " & lngCorrectAns & ", " & tmpAns & ", " & boolAns & ", '" & Date & "', " & Session.Value & ");"
If CurrentRecord < RecordsetClone.RecordCount Then
' Next Record
DoCmd.GoToRecord , "frmTest", Record:=acNext, Offset:=1
Else
If lngSkip > 0 Then
Find_SkipRecord
boolRedisplay = True
MsgBox " lngTestRcd = " & lngTestRcd
Dim tmpr As Long
tmpr = 3
DoCmd.GoToRecord , "frmTest", Record:=tmpr
Else
DoCmd.Close acForm, "frmTest", acSaveNo
DoCmd.OpenForm "frmUserTestResults", acNormal
End If
End If
Else
' Update existing record lngTestRcd
dbs.Execute "Update tblTestHistory (SET ([lngUserAns] = " & tmpAns & ", [boolCorrect] = " & boolAns & ") " _
& "WHERE ([ID_History] = " & lngTestRcd & ");"
lngSkip = lngSkip - 1
If lngSkip > 0 Then
Find_SkipRecord
DoCmd.GoToRecord , Record:=acFirst
Else
End If
End If
ExitPoint:
On Error GoTo 0
dbs.Close
Exit Sub
ErrorHandler:
Call LogError(Err.Number, Err.Description, "frmTest-Cmd_Submit")
Resume ExitPoint
End Sub
Posted by: desertscroller@cox.net
Reply via web post | • | Reply to sender | • | Reply to group | • | Start a New Topic | • | Messages in this topic (1) |
Tidak ada komentar:
Posting Komentar