Results 1 to 5 of 5
  1. #1
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936

    Best way to handle non-insert

    I have a form where the user can select an item, the form filters and the record is displayed. There is a "New" button for them to add a new record, this does DoCmd.GoToRecord,,,acNewRec. They enter the information and click on an "Add" button which does a whole bunch of stuff. However, if they go direct from the "New" button to selecting an item (without clicking Add), errors occur - in this case some required fields haven't been entered.

    I would like to be able to intervene and cancel the insert, same as user hitting 'esc', but I haven't been able to figure out where or how to handle this.



    Any help would be appreciated.

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,740
    I've used something like this. This is modified a bit to remove some of my application specific code, so it's untested as is.

    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
        Select Case Me.NewRecord
            Case True
    		'check global var or tempvar set when ADD button clicked (ADD Flag)
                   If fcnAddHasBeenClicked = true then
    			'Clear the ADD flag here
    			Exit Sub
    		Else               
    	               'various fields that need to be blanked
    			cboucFrom.Undo
    	                cboucTo.Undo
    	                Me.Undo
    	                Cancel = True
    		end if	 
            Case False   'existing record being changed
        End Select
    'Clear the ADD  Flag here...
    End Sub

  3. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    How about disabling the "New" button until the user has clicked the "add" button?

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    RuralGuy - incorrect sequence of events.

    davegri - thanks, I will try that.

  5. #5
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    This code is run immediately the Add button is clicked, so I cannot add a new record as it cancels the new record as soon as I click on Add.

    Solution: added the Select Case/Me.Undo in the AfterUpdate event of the selection combobox.

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

Similar Threads

  1. category handle
    By aladdin88 in forum Access
    Replies: 3
    Last Post: 01-14-2015, 12:15 PM
  2. how to Handle NULLS in MsAccess
    By skurra in forum Access
    Replies: 5
    Last Post: 11-05-2014, 02:00 PM
  3. Best way to handle this Web Database
    By tucker1003 in forum Database Design
    Replies: 8
    Last Post: 03-18-2011, 12:14 PM
  4. 'handle' command
    By B Mellars in forum Access
    Replies: 6
    Last Post: 12-14-2010, 01:23 PM
  5. What is the best way to handle photos?
    By TundraMonkey in forum Database Design
    Replies: 2
    Last Post: 08-12-2009, 10:52 PM

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