helpneeded
Programmer
I'm currently writing some code that opens up a recordset tblTitle, finds the last library number, increments it by one and then copies the value back to a new record in that recordset together with some values from a form or adds a copy to another table if the library number exists. When adding a new title it randomly crashes when creating a new record. It seems like it hasn't picked up the last library number value in the recordset. It works fine when there is only one field in the table, but the actual table has 25 fields. I have found one work round, create a new one row table to store the last library number, seems like a cack way round the problem. If anyone can help I will sleep easier at night.
Dim db As DATABASE
Dim rst As Recordset
Dim rstClone As Recordset
Dim rstCopy As Recordset
Dim GetBookNum As Integer
Dim GetCopyNum As Integer
Dim StrLibNum As String
Set db = CurrentDb
Set rst = db.OpenRecordset("tblTitle"
Set rstClone = Me.RecordsetClone
rstClone.Bookmark = Me.Bookmark
If Me.strStatus = "new" Then
rst.MoveLast
GetBookNum = rst!lngLibrarynumber + 1
'Debug.Print GetBookNum
rst.AddNew
rst!lngLibrarynumber = GetBookNum
rst!strTitle = Me.strTitle
rst.Update
rst.Close
rstClone.Close
db.Close
Else
StrLibNum = Me.lngLibrarynumber
strSql = "SELECT lngLibraryNumber, lngCopyNumber, strOrderReference FROM tblCopies WHERE [lngLibraryNumber]=" & StrLibNum & " order by lngCopyNumber"
Set rstCopy = db.OpenRecordset(strSql)
rstCopy.MoveLast
GetCopyNum = (rstCopy!lngCopyNumber) + 1
rstCopy.AddNew
rstCopy!lngLibrarynumber = Me.lngLibrarynumber
rstCopy!strOrderReference = Me.strOrderNumber
rstCopy!lngCopyNumber = GetCopyNum
rstCopy.Update
rstCopy.Close
rstClone.Close
db.Close
End If
Dim db As DATABASE
Dim rst As Recordset
Dim rstClone As Recordset
Dim rstCopy As Recordset
Dim GetBookNum As Integer
Dim GetCopyNum As Integer
Dim StrLibNum As String
Set db = CurrentDb
Set rst = db.OpenRecordset("tblTitle"
Set rstClone = Me.RecordsetClone
rstClone.Bookmark = Me.Bookmark
If Me.strStatus = "new" Then
rst.MoveLast
GetBookNum = rst!lngLibrarynumber + 1
'Debug.Print GetBookNum
rst.AddNew
rst!lngLibrarynumber = GetBookNum
rst!strTitle = Me.strTitle
rst.Update
rst.Close
rstClone.Close
db.Close
Else
StrLibNum = Me.lngLibrarynumber
strSql = "SELECT lngLibraryNumber, lngCopyNumber, strOrderReference FROM tblCopies WHERE [lngLibraryNumber]=" & StrLibNum & " order by lngCopyNumber"
Set rstCopy = db.OpenRecordset(strSql)
rstCopy.MoveLast
GetCopyNum = (rstCopy!lngCopyNumber) + 1
rstCopy.AddNew
rstCopy!lngLibrarynumber = Me.lngLibrarynumber
rstCopy!strOrderReference = Me.strOrderNumber
rstCopy!lngCopyNumber = GetCopyNum
rstCopy.Update
rstCopy.Close
rstClone.Close
db.Close
End If