Code to avoid error - "Can't Go To Specified Record"

Posted on 2012-09-06
Last Modified: 2012-10-15
What VBA code in the property sheet for this form would help me by pass the error "Can't Got To Specified Record".

When the form is in "edit mode" and I try and advance to the next record, the aforementioned error is displayed.

If the form is in edit mode, and I attempt to move to the next record, I would like the form to save the record... and then advance to the next record.
Status of record prior to display of error message.Form-ProcModule.jpg
Question by:geekmee2

    Author Comment

    Here is the property sheet for the "Next_Record" command button... so I know I am close:

    Property sheet for Next_Record command button on form.
    (I am not a programmer, but learning the basics of VBA for Access)
    LVL 20

    Expert Comment

    Without seeing more of your code it is hard to give specifics.  Hopefully I can help guide you some.  Ask questions as you need, as I am not sure how much programming you have done.

    In general what you need to do is add in code at the beginning of the Next_Record event that calls the same code as is run by the save button on your form.  You will also need to find the code that is called when the Save button is clicked.  A simple fix is to just copy that code that saves the record and put that at the beginning of the code for the Next_Record event.  However, a better coding practice is to create a separate procedure that both the Save Button and the Button call.  That way the code is in one place and not two.  It is easier to maintain.


    Author Comment

    I understand what you are saying overall, from my readings on procedures... but I guess there is only so much reading you can do... I guess it's time to start testing my assumptions...and start learning from my mistakes to get a clearer concept.

    I have noticed that the behavior of the very last field "Followup"...If I tab out of that field it saves the record automatically.

    In the Procedures window I see a subroutine for the Followup field:

     "Follow_Up_BeforeUpdate (Cancel As Integer)"

    If I follow this convention it looks like I could create a subroutine for the Next_Record command button:

     "Next_Record_BeforeUpdate (Cancel As Integer)"

    Am I on the right path?
    LVL 20

    Expert Comment

    Yes you are heading the in the right direction.  You might want to look at your code to see if there are any Next_Record procedures already defined and what they do.  If there are none (which may be the case in Access), then create the before update procedure.  Then look at the code in "Follow_Up_BeforeUpdate (Cancel As Integer)".  You will need to place some and maybe all that code in "Next_Record_BeforeUpdate (Cancel As Integer)"

    LVL 74

    Accepted Solution

    The issue here is that you are opening your form to the "Last" record.

    If you are on the last record, then that is literally the: "Last Record".
    Hence it is impossible to go to the "Next Record".
    This is why you are getting the error.

    So if you are on the last record, then the "Next" record would actually have to be a *New* record.

    So then we need to go back to the start....
    Why are you opening the form on the last record?
    A table in Access can be sorted in any way the user wants.
    Hence the "Last" record, can be different each time.
    If you really want to open the form to the *LAST ADDED* record, then you need to add a date stamp field to your table with a default value of: Now().
    Then sort the recordsource of the form by this date field. (so the higheset date is first record)
    Then all you have to do is Open the form.
    Then this should all work normally.


    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
    Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
    In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
    With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now