New Record Not Working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jollywg
    New Member
    • Mar 2008
    • 158

    #1

    New Record Not Working

    I have two forms and when form 2 is loaded it is supposed to create a new record. This was working only when there were other records in the table. I have cleared out the records in the table that form 2 is built off of and now when i launch it, form 2 gives me this error

    Run-time error '2105': You can't go tot he specified record.

    heres my code that it brings up when I click Debug

    DoCmd.GoToRecor d , , acNewRec

    Is there a way to add a new record without using the GoToRecord command in VBA? I think that this would fix my problem.

    Thanks!
  • nico5038
    Recognized Expert Specialist
    • Nov 2006
    • 3080

    #2
    Originally posted by Jollywg
    I have two forms and when form 2 is loaded it is supposed to create a new record. This was working only when there were other records in the table. I have cleared out the records in the table that form 2 is built off of and now when i launch it, form 2 gives me this error

    Run-time error '2105': You can't go tot he specified record.

    heres my code that it brings up when I click Debug

    DoCmd.GoToRecor d , , acNewRec

    Is there a way to add a new record without using the GoToRecord command in VBA? I think that this would fix my problem.

    Thanks!
    Are you sure form 2 has the "Allow Additions" property set to "Yes" ?
    Another option is to create a form 2 with the "Data Entry" property set to "Yes" to make sure a new record is forced each time.

    Nic;o)

    Comment

    • missinglinq
      Recognized Expert Specialist
      • Nov 2006
      • 3533

      #3
      I'm not sure exactly what's going on with your form. How exactly did you "clear out the records in the table?" You didn't, by chance, simply delete the table, did you? That might cause the error you cited, since the form would no longer have a valid Record Source.

      I assume that the line

      DoCmd.GoToRecor d , , acNewRec

      is in the form's OnLoad event, which is where it belongs. Placement elsewhere might cause the error. If the underlying table exists but is empty, this code shouldn't cause an error.

      If your intent for this form is to only allow the adition of records, and not allow the viewing of existing records then
      • Delete the line DoCmd.GoToRecor d , , acNewRec
      • In Design View for the form goto Properties - Data and set the Data Entry Property to Yes
      This will only allow new recordsto be added.

      Linq ;0)>

      Comment

      Working...