Error 3211: The database engine could not table 'tblqsts', already in use

  • Thread starter Thread starter Samantha R via AccessMonster.com
  • Start date Start date
S

Samantha R via AccessMonster.com

Full error: The database could not lock table 'tblqsts' because it is already
in use by another person or process.

This is my function:
Public Function RandRec() As Integer
'select random question
Dim firq As Integer
Dim curq As Integer
Dim i As Integer
Dim Rec As DAO.Recordset

Set Rec = Nothing
DoCmd.SetWarnings False
DoCmd.DeleteObject acTable, "tblqsts"
DoCmd.OpenQuery "qrytest", acViewNormal, acReadOnly 'make-table query
that opens 'tblquestion' and puts all relevant values into new table
'tblqsts', THIS IS THE ERROR LINE
DoCmd.SetWarnings True
If CountQuestions >= 10 Then
Set Rec = CurrentDb.OpenRecordset("tblqsts", dbOpenTable)
Rec.MoveFirst
firq = Int((10 - 1 + 1) * Rnd + 1)
Rec.Move firq - 1
RandRec = CInt(Rec.Fields(0)) 'this is the random question code
DoCmd.OpenForm "frmtest"
Else
MsgBox ("Sorry, there are not enough questions for this subject.
Please try another one.")
End If
Set Rec = Nothing
End Function

I have lots of other code that I can post, but I think much of it will be
irrelevant. I use the function by 'Call RandRec'. I have deleted the table
before the make table thing, so I don't see how it can be used.
CountQuestions is the following function:

Public Function CountQuestions() As Integer
CountQuestions = CurrentDb.TableDefs("tblqsts").RecordCount
DoCmd.Close acTable, "tblqsts", acSaveYes
End Function

I can't see how it is already in use. Can anybody help please?
 
RESOLVED: I have added the line 'On Error Resume Next' at the start of my
code. While technically not resolving the issue, it does bypass it and my
code works fine.
 
Back
Top