Onderstaand een functie welke een versienummer verhoogd in Access. De VBA code werkt echter niet als ik een record wil editen met findfirst:
De foutmelding is 3251: "De bewerking is niet beschikbaar voor dit object (komt vanaf de procedure welke deze functie aanroept".
Met de volgende code lukt het wel maar volgens mij zou dit op deze manier niet hoeven, iemand een idee wat er bovenstaand mis gaat?
De foutmelding is 3251: "De bewerking is niet beschikbaar voor dit object (komt vanaf de procedure welke deze functie aanroept".
Code:
Public Function Version(lngID As Long)
On Error GoTo ErrorHandler
Set dbs = CurrentDb
Set tdfs = dbs.TableDefs
Set rst = dbs.OpenRecordset("tblCSD")
intNo = Nz(DMax("[Versie]", "tblCSD", "[CSD_ID] = " & lngID), 0)
Debug.Print "No. " & intNo
strNextNo = CStr(intNo + 1)
Debug.Print "Next No. " & strNextNo
strSearch = "[CSD_ID] = " & lngID
With rst
.FindFirst strSearch
If .NoMatch = False Then
.Edit
![Versie] = strNextNo
.Update
.Close
End If
.Close
End With
ErrorHandlerExit:
Exit Function
ErrorHandler:
MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
Resume ErrorHandlerExit
End Function
Met de volgende code lukt het wel maar volgens mij zou dit op deze manier niet hoeven, iemand een idee wat er bovenstaand mis gaat?
Code:
Public Function Version(lngID As Long)
On Error GoTo ErrorHandler
Set dbs = CurrentDb
Set tdfs = dbs.TableDefs
Set rst = dbs.OpenRecordset("tblCSD")
intNo = Nz(DMax("[Versie]", "tblCSD", "[CSD_ID] = " & lngID), 0)
Debug.Print "No. " & intNo
strNextNo = CStr(intNo + 1)
Debug.Print "Next No. " & strNextNo
strSearch = "[CSD_ID] = " & lngID
With rst
If Not .BOF And Not .EOF Then
.MoveLast
.MoveFirst
Do While (Not .EOF)
If ![CSD_ID] = lngID Then
.Edit
![Versie] = strNextNo
.Update
.Close
GoTo ErrorHandlerExit
End If
.MoveNext
Loop
End If
.Close
End With
ErrorHandlerExit:
Exit Function
ErrorHandler:
MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
Resume ErrorHandlerExit
End Function