Any help, specific or general would be appreciated.
I've been wrestling with this for a while now, I think it's because I don't think I understand what's happening fundamentally when a user creates a new record.
Problem explanation:
-I have a heavily coded form that contains customer data.
-Each customer has a primary key ID field.
-There are several other foreign keys on the field (like orders) that can't be null if there's a customer record
-User goes into a new record.
-User starts filling out form.
-User regrets it and wants to bail out.
-User somehow forgets to input primary key field, or one of the other fields that are required due to relationships.
-User can't back out of the record at all, because the form keeps throwing back integrity errors.
-User can hit "escape" 3 or 4 times to cancel the new record, but this is non-intuitive and impractical
I want to code the cmdPreviousRecord to ask the user if they wish to cancel the new record, and if so, to get rid of the incomplete record (which may be missing key fields) and go back to the last record in the recordset.
This code does not work (i may have commented out some of the if's incorrectly, but I think you get the idea):
Ah say, there's somethin' a little "eeeeeeee" 'bout a boy who don't like basbawl...
I've been wrestling with this for a while now, I think it's because I don't think I understand what's happening fundamentally when a user creates a new record.
Problem explanation:
-I have a heavily coded form that contains customer data.
-Each customer has a primary key ID field.
-There are several other foreign keys on the field (like orders) that can't be null if there's a customer record
-User goes into a new record.
-User starts filling out form.
-User regrets it and wants to bail out.
-User somehow forgets to input primary key field, or one of the other fields that are required due to relationships.
-User can't back out of the record at all, because the form keeps throwing back integrity errors.
-User can hit "escape" 3 or 4 times to cancel the new record, but this is non-intuitive and impractical
I want to code the cmdPreviousRecord to ask the user if they wish to cancel the new record, and if so, to get rid of the incomplete record (which may be missing key fields) and go back to the last record in the recordset.
This code does not work (i may have commented out some of the if's incorrectly, but I think you get the idea):
Code:
Private Sub cmdPrevious_Click()
On Error GoTo Err_cmdPrevious_Click
On Error Resume Next
If Me.NewRecord = True Then
If Me.txtMemberID.Value = "" Or IsNull(Me.txtMemberID.Value) Then
If MsgBox("You want out?", vbYesNo, "Get outta here") = vbYes Then
'this is not the way to do it, but hey, I tried.
SendKeys "{ESC}"
SendKeys "{ESC}"
'This doesn't work at all, even when the new record gets cancelled successfully - Why not?:
DoCmd.GoToRecord , , acPrevious
End If
Else
DoCmd.GoToRecord , , acPrevious
End If
Else
DoCmd.GoToRecord , , acPrevious
End If
' DoCmd.GoToRecord , , acPrevious
Exit_cmdPrevious_Click:
Exit Sub
Err_cmdPrevious_Click:
MsgBox Err.Description
Resume Exit_cmdPrevious_Click
End Sub
Ah say, there's somethin' a little "eeeeeeee" 'bout a boy who don't like basbawl...