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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error adding record

Status
Not open for further replies.

jordanh

Technical User
Nov 11, 2002
47
GB
I have a form with listboxes from which a user selects a 'group' then if they click on 'add new record' I need to open up the editing form and populate a few fields.

My problem is that when I click on 'add new record' the code gives me run-time error 2105 (You can't go to the specified record. You may be at the end of a record sheet)at the line "DoCmd.GoToRecord , , acNewRec"

Below is my code in full, I'd really appreciate it if anyone can help here, I'm sure it's something simple but I'm stumped! Thanks,

Jordan

Private Sub add_system_Click()

Dim agroup, asys, asub, aitem As String
If Not IsNull(Me!GroupList) Then
agroup = Me!GroupList
End If

If IsNull(Me!GroupList) Then
MsgBox "Please select a System Group to add System to", vbOKOnly + vbExclamation, "Error"
Exit Sub
End If

DoCmd.OpenForm "add_item"
DoCmd.GoToRecord , , acNewRec

Forms!add_item![SysGroup] = "'" & agroup & "'"
Forms!add_item![Sub-System] = "Overall System"
Forms!add_item![R2] = 0
Forms!add_item![R3] = 0
Forms!add_item![Plant item] = "Overall System"
Forms!add_item![Manufacturer / type] = "See individual subsystems"
Forms!add_item![Zone code] = "See individual subsystems"
Forms!add_item!System.SetFocus

End Sub
 
I think what is happening here is that the docmd.gotorecord,,,acnewrec is referencing the current form, not the one you just opened.

You can try a number of things:

when you open the form try opening it with the statement:
docmd.openform "add_item", , , , acFormAdd
(this opens the form and automatically goes to a new record)

or change the properties of the form to:

AllowAdditions = true
DataEntry = true
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top