Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exit newrecord and go to a specific record

Status
Not open for further replies.

marabozu

Programmer
Jan 3, 2001
36
0
0
US
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top