Results 1 to 4 of 4
  1. #1
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566

    Msgbox on Change of Control

    Hi Everyone



    On a Continuous Form I have a Yes/No Control named "Marker"

    What I need to happen is :-

    If the Control is currently set as "Yes" and the user changes it to "No" Then Popup a MsgBox with the Message "Are you sure you want to change this to No?" with Buttons for Yes or Cancel

    I have placed the following code in the Before Update of the Control:-

    Code:
    Private Sub PO_Schedule_Marker_BeforeUpdate(Cancel As Integer)
    
    
    10        On Error GoTo PO_Schedule_Marker_BeforeUpdate_Error
    
    
          Dim strMessage As String
              Dim intResponse As Integer
              
             
    20        If Me.PO_Schedule_Marker = False Then
              ' Display the custom dialog box.
    30        strMessage = "Would you like to Change the current Marker to NO?"
    40        intResponse = MsgBox(strMessage, vbYesNo + _
                  vbQuestion, _
                  "Continue Change?")
              
              ' Check the response.
    50        If intResponse = vbYes Then
                  '.....
    60        Else
    70            Cancel = True
    80        Me.PO_Schedule_Marker.SetFocus
    90        End If
    100       End If
    110       Exit Sub
           
    
    
    
    
              
    120       On Error GoTo 0
    130       Exit Sub
    
    
    PO_Schedule_Marker_BeforeUpdate_Error:
    
    
    140       MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure PO_Schedule_Marker_BeforeUpdate, line " & Erl & "."
    
    
    End Sub
    When I change the value to No I get the Popup Message as expected but when I click the No Button I get the following error:-

    Click image for larger version. 

Name:	error.JPG 
Views:	16 
Size:	27.1 KB 
ID:	45900

    Any help in showing me where I am going wrong appreciated.
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  2. #2
    Minty is online now VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Remove the setfocus line - you can't set the focus on what will be the current control if you cancel the event.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,944
    Well firstly, as you have updated the control, I would expect the code to go in the AfterUpdate event?

    If you cancel the BeforeUpdate, doesn't the focus remain on that control?

    The error message is somewhat self evident, I would have thought?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Hi Minty

    That works just great

    Many thanks for all contributions.
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

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

Similar Threads

  1. Change control's colors
    By Chas in forum Access
    Replies: 5
    Last Post: 12-07-2020, 04:22 PM
  2. Change top of each control
    By AmanKaur123 in forum Programming
    Replies: 8
    Last Post: 01-24-2017, 08:38 PM
  3. Replies: 2
    Last Post: 10-03-2014, 10:07 AM
  4. a loop using vba to change control name
    By Chuck55 in forum Programming
    Replies: 4
    Last Post: 04-23-2012, 09:23 PM
  5. conditional msgbox in a control
    By raton in forum Forms
    Replies: 6
    Last Post: 03-29-2012, 09:43 AM

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