Add new record to the table by click on the button in Microsoft Access -


in ms access form want implement separate button, adds new record table. in order added button , attached button event:

private sub btnaddrec_click()     refresh     codecontextobject     on error resume next     docmd.gotorecord , , acnewrec     if err.number <> 0     btnaddrec.enabled = false     end if     end end sub 

everything ok when open window , click btnaddrec button, problem when first of perform navigation through existed records , after click on button. got runtime error: 2105: «you can't go specified record. may @ end of recordset».

how solve issue, need have ability add new record on click on specific button, no matter, have walked or not walked through records before.

thanks.

i created simple form field call description (and autonumber) , created button code follows click event. filled number of records , navigated through them, clicked addnewrec button. form navigated new record without issues. able click addnewrec button directly after opening form successfully.

private sub btnaddrec_click() on error goto err1   docmd.gotorecord , , acnewrec   exit sub err1:   description.setfocus   btnaddrec.enabled = false   msgbox (err.description)  end sub 

the differences code included removing refresh , statement, handing error, setting focus before disabling button , showing user error description. not know if form similar, should work if , understood problem correctly.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -