Results 1 to 8 of 8
  1. #1
    vector39 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    May 2017
    Posts
    76

    Run-time error 2105 prompt message once clear button is pressed

    Hi everyone



    Click image for larger version. 

Name:	agencydeets.PNG 
Views:	19 
Size:	20.5 KB 
ID:	30284


    Just wanted your thoughts on something. So I created a form, as seen above that allows users to add new or edit existing agency information. On the main table, for the agency field, under "General", I set Required to Yes. Thus users MUST provide an agency name as this cannot be blank. Now for whatever crazy reason the user starts filling out the form, hitting save, without an agency name, they will receive a prompt message saying:



    You must enter a value in the 'AgencyINFO.Agency' table



    Everything is good so far. Now, I think most people would go "Oh shoot I forgot to enter their name" and type in an agency name. Problem solved. However, if for whatever reason the user decides they want to delete everything they just typed, they will be prompted with this message:



    Run-time error '2105':


    You can't go to the specified record



    And when the debug window pops up, the vba for the Clear button shows up as:
    Code:
    Option Compare Database
    
    
    Private Sub cmdClear_Click()
    DoCmd.GoToRecord , , acNewRec //this part is highlighted yellow
    End Sub

    I can't think of many times for this particular project where users would start entering an agency's info without the agency name. Seems kind of obvious you'd have an organization's name first then start filling out their information. But I'm just thinking if they started filling out their info (e.g. address, email, phone number, etc.) without an agency name but decide they made a mistake and want to clear all the fields, they will be prompted with an error message they won't know how to interact with. From a developer's side, is there a way I can prevent this run time error? Thank you!

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    In your error procedure for cmdClear_Click:
    Code:
    Select case err
        case 2105    'ignore
        case else
            Msgbox err & " " & err.description
    end select
    Last edited by davegri; 09-12-2017 at 10:43 AM. Reason: clarif

  3. #3
    vector39 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    May 2017
    Posts
    76
    Hi davegri

    I implemented your code:
    Code:
    Option Compare Database
    
    
    Private Sub cmdClear_Click()
    Select Case Err
        Case 2105    'ignore
        Case Else
            MsgBox Err & " " & Err.Description
    End Select
    
    
    DoCmd.GoToRecord , , acNewRec
    End Sub
    This image appears, whenever the form opens and I hit clear right away:
    Click image for larger version. 

Name:	zero.PNG 
Views:	19 
Size:	3.7 KB 
ID:	30287

    And when I click 'Ok' and in the 'PhoneNumber' field, there is a 0, in place of the default value (000-000-0000)

    Also, when I play around with entering agency info without putting an agency name, I went to hit 'Clear' and the same error occured:
    Click image for larger version. 

Name:	debug.PNG 
Views:	19 
Size:	30.9 KB 
ID:	30288

    And DoCmd.GoToRecord , , acNewRec still came back yellow in the debug window. Thoughts? And thank you.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    I think the intention was to use that code within a proper error trap:

    http://www.baldyweb.com/ErrorTrap.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    vector39 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    May 2017
    Posts
    76
    Thank you!

  6. #6
    Join Date
    Apr 2017
    Posts
    1,673
    Easiest will be in OnCurrent event disable all controls except agency name control and Clear button when agency name is not entered, and enable all controls otherwise.

    Then in agency name control's AfterUpdate event, you also have to set form's controls enabled/disabled depending the value of agency name entered or deleted, and the same for Clear button.

    I.e. set the form so up, that user can't save the record without entering agency name at all.

  7. #7
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    The reason you are getting the error is that your "Clear" button code is not clearing anything. It is trying to go to a new record, meaning it has to try to save the current record first. But it can't save the current record because it is not valid, so you get an error.

    Your "Clear" button just needs to clear the current record with me.Undo. It doesn't need to go to a new record because it is already on one:

    Code:
    Private Sub cmdClear_Click()
      me.Undo
      docmd.gotocontrol "AgencyName"  ' Enter the actual name of your control
    End Sub

  8. #8
    vector39 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    May 2017
    Posts
    76
    Thank you John_G

    It worked like a charm!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Prompt Pop Up Alert Message on clicking Form Button
    By Alexandru Human in forum Forms
    Replies: 2
    Last Post: 09-28-2015, 07:12 PM
  2. Replies: 2
    Last Post: 08-28-2014, 11:47 AM
  3. Replies: 1
    Last Post: 01-10-2014, 09:51 AM
  4. Replies: 1
    Last Post: 06-04-2012, 03:37 PM
  5. Replies: 3
    Last Post: 04-17-2012, 03:26 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums