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
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