B
BruceM
I have code that assigns a primary key field in a particular format. The
primary key is the report number (report in the generic sense, that is, not
an Access object) in the format RPT 05-01, RPT 05-02, and so forth. That is
fine, as long as there is only one user. While multiple users are not
likely, it could happen, so I attempted something I got from Roger Carlson's
site to avoid duplicates. There is a function something like this:
Function IncrementRPT(DataErr)
If DataErr = 3022 Then
Call AssignNumber
IncrementRFI = acDataErrContinue
End If
End Function
AssignNumber is a sub that uses DMax and other manipulations to produce a
report number. It works as expected.
To go with this, in the Form's Error event I have:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
Response = IncrementRFI(DataErr)
End Sub
Both pieces of code have error handling, not included here. Also, there is
a message box in the Error event advising the user that the number will
change.
However, it doesn't seem to work as I would hope. One difficulty I am
having trying to grasp this is that I don't really understand the form's
Error event. My form has a Before Update event that performs some validation
(making sure all required fields are completed). I have several ways of
saving the record (causing Before Update to run). If, for instance, I use a
command button to save the record, error 3022 (duplicate PK) is a command
button error. I know this because my error handling identifies the event in
which the error occurs. I can't seem to find a way for the database to
determine that the PK is already in use, and to go back for another one.
Perhaps I need to refresh the form, or something like that, so that the new
number appears? If I could see the message box (in the form's Error event)
advising the user that there is a new number I would be more confident about
this. Can anybody help get me on track here? I think I may be getting
close, but something is missing.
primary key is the report number (report in the generic sense, that is, not
an Access object) in the format RPT 05-01, RPT 05-02, and so forth. That is
fine, as long as there is only one user. While multiple users are not
likely, it could happen, so I attempted something I got from Roger Carlson's
site to avoid duplicates. There is a function something like this:
Function IncrementRPT(DataErr)
If DataErr = 3022 Then
Call AssignNumber
IncrementRFI = acDataErrContinue
End If
End Function
AssignNumber is a sub that uses DMax and other manipulations to produce a
report number. It works as expected.
To go with this, in the Form's Error event I have:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
Response = IncrementRFI(DataErr)
End Sub
Both pieces of code have error handling, not included here. Also, there is
a message box in the Error event advising the user that the number will
change.
However, it doesn't seem to work as I would hope. One difficulty I am
having trying to grasp this is that I don't really understand the form's
Error event. My form has a Before Update event that performs some validation
(making sure all required fields are completed). I have several ways of
saving the record (causing Before Update to run). If, for instance, I use a
command button to save the record, error 3022 (duplicate PK) is a command
button error. I know this because my error handling identifies the event in
which the error occurs. I can't seem to find a way for the database to
determine that the PK is already in use, and to go back for another one.
Perhaps I need to refresh the form, or something like that, so that the new
number appears? If I could see the message box (in the form's Error event)
advising the user that there is a new number I would be more confident about
this. Can anybody help get me on track here? I think I may be getting
close, but something is missing.