Hi,
I have a form that, when I'm introducing a new record, if the primary key is already being used in a previous record, it exits the new record and go to the respective record. Well, this is what I want to have, but i'm having a problem I can exit the new record "mode". Here's the code:
Private Sub SiteCode_LostFocus()
If Me.Form.NewRecord Then
Form_BeforeInsert 0
End If
End Sub
Private Sub Form_BeforeInsert(Cancel As Integer)
SC = Me.SiteCode.Value
For c = 0 To Me.SiteCode.ListCount - 1
If SC = Me.SiteCode.ItemData(c) Then
Me.SiteName.SetFocus
Cancel = True
RecordToGo = c + 1
DoCmd.GoToRecord acDataForm, "Frm_All_Pages", acGoTo, RecordToGo
Me.SiteCode.SetFocus
Exit Sub
Next c
End Sub
The error I get is:
Run-time error 2105
You can't go to the specified record.
Well, if i'm not inserting a new record I can go to the record but else I can't
Can anyone help me on this one?
thank you
I have a form that, when I'm introducing a new record, if the primary key is already being used in a previous record, it exits the new record and go to the respective record. Well, this is what I want to have, but i'm having a problem I can exit the new record "mode". Here's the code:
Private Sub SiteCode_LostFocus()
If Me.Form.NewRecord Then
Form_BeforeInsert 0
End If
End Sub
Private Sub Form_BeforeInsert(Cancel As Integer)
SC = Me.SiteCode.Value
For c = 0 To Me.SiteCode.ListCount - 1
If SC = Me.SiteCode.ItemData(c) Then
Me.SiteName.SetFocus
Cancel = True
RecordToGo = c + 1
DoCmd.GoToRecord acDataForm, "Frm_All_Pages", acGoTo, RecordToGo
Me.SiteCode.SetFocus
Exit Sub
Next c
End Sub
The error I get is:
Run-time error 2105
You can't go to the specified record.
Well, if i'm not inserting a new record I can go to the record but else I can't
Can anyone help me on this one?
thank you