Hi,
I have a form which uses table 'Patients' as Record Source and type Dynaset. I have a 8 digit text id field which starts with 'PT' (PT000001). I wrote the following code to get the next maximum ID on a new record.
But when I try to add new record, I get the following error.
"The table Patients is already opened exclusively by another user, or it is already open through the user interface and cannot be manipulated programmaticall y. (Error 3008)"
Could anyone suggest a work around on this issue?
Thanks,
Robin
I have a form which uses table 'Patients' as Record Source and type Dynaset. I have a 8 digit text id field which starts with 'PT' (PT000001). I wrote the following code to get the next maximum ID on a new record.
Code:
Private Sub Form_Current()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim sql As String
Dim strNextID As String
If Me.NewRecord Then
sql = "SELECT TOP 1 CInt(Mid([Id],3,8)) AS MaxID " & _
"FROM Patients " & _
"ORDER BY CInt(Mid([Id],3,8)) DESC ;"
Set db = CurrentDb
Set rs = db.OpenRecordset(sql, dbOpenDynaset, dbOptimistic)
strNextID = "PT" & String(6 - Len(rs!maxid), "0") & rs!maxid + 1
Me.Id = strNextID
Me.Id.SetFocus
End If
End Sub
"The table Patients is already opened exclusively by another user, or it is already open through the user interface and cannot be manipulated programmaticall y. (Error 3008)"
Could anyone suggest a work around on this issue?
Thanks,
Robin
Comment