Results 1 to 2 of 2
  1. #1
    mortonsafari is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2015
    Location
    Brisbane, Queensland, Australia
    Posts
    39

    Using Event Code to Disable another Event Code

    I have a form where the first input control is the person’s Surname, and the second is the person’s First Name.
    I am trying to prevent users from overtyping the Surname if they inadvertently use a current record, rather that the new record.
    The following code shows my actions in dealing with Surname control data entry and then moving to the First Name control and then doing a Disable action on the Surname control.
    The Before Update checks for New Record and ignores message.
    After the record is Updated, the After Update moves to the next control and Disables the Surname control.
    I also have the Lost Focus set to act the same way so that the Surname control Disables when it loses the focus after originally being Enabled and selectable.
    What I need to do is the have an “Edit Surname” button which will Enable the Surname control and allow the Surname to be changed (when required).
    What is the best way to allow the Surname control to be re-Enabled?

    BEFORE UPDATE
    [Private Sub CSurname_BeforeUpdate(Cancel As Integer)
    'If a new record, ignore message, if not - error message
    If Me.NewRecord Then
    Cancel = False


    Else

    If MsgBox("You are about to overwrite this Surname -" & Chr(13) & _
    "Are you sure you want to do this?" & Chr(13) & Chr(13) & _
    "Click YES to overwrite and continue" & Chr(13) & Chr(13) & _
    "Click NO to leave original name", _
    vbCritical + vbYesNo + vbDefaultButton2, _
    "Surname Error") = vbNo Then
    Cancel = True
    Me.Undo
    End If
    End If
    End Sub]


    AFTER UPDATE
    [Private Sub CSurname_AfterUpdate()
    'Move to First Name field
    DoCmd.GoToControl "CFirstName"
    'Disable Surname field
    Me.CSurname.Enabled = False

    End Sub]

    LOST FOCUS
    [Private Sub CSurname_LostFocus()
    'Move to First Name field
    DoCmd.GoToControl "CFirstName"
    'Disable Surname field
    Me.CSurname.Enabled = False
    End Sub]

    Thanks for any assistance.
    Kind Regards
    mortonsafari

  2. #2
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,412
    What I need to do is the have an “Edit Surname” button which will Enable the Surname control and allow the Surname to be changed (when required).
    What is the best way to allow the Surname control to be re-Enabled?
    Maybe I don't understand the problem. The click event of the 'Edit Surname' button would be
    Code:
    Me.CSurname.Enabled = True

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

Similar Threads

  1. Replies: 2
    Last Post: 06-02-2016, 12:26 PM
  2. On Event VBA Code Help
    By NickWren in forum Programming
    Replies: 3
    Last Post: 02-19-2016, 08:27 AM
  3. Replies: 7
    Last Post: 05-28-2013, 09:11 AM
  4. How to suppress Current event code?
    By RonL in forum Forms
    Replies: 5
    Last Post: 04-12-2013, 12:43 PM
  5. How to put code in form event.
    By rogdawg in forum Forms
    Replies: 4
    Last Post: 08-06-2010, 03:38 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