MsgBox PopUP Twice with checkbox

Ciccio86

New Member
Joined
Feb 3, 2023
Messages
27
Office Version
  1. 365
Platform
  1. Windows
Hi, when i tick a checkbox i got the msgbox popup twice
Checkbox CODE
VBA Code:
Private Sub CheckBox3_Click() 
    If Prev(chk) = "NO1" Then
        chk.Object = False
        Exit Sub
    End If

End Sub


Function CODE
VBA Code:
Function Prev(chk As OLEObject)
Dim PrevValue As Variant
 
    If TypeName(chk.Object) = "CheckBox" Then
    PrevValue = chk.TopLeftCell.Offset(-1, 0).Value
    If PrevValue = "0" Then
        chk.TopLeftCell.Offset(0, 0).Value = "0"
        chk.Object = False
        MsgBox "Not correct"
        Prev = "NO1"
    Else
        chk.TopLeftCell.Offset(0, 0).Value = "1"
        End If
    End If

End Function

Tried to fix like this as recommended in my last post but it didn't work
VBA Code:
Dim runChkBox As Boolean

Private Sub CheckBox3_Click()
    Dim chk As OLEObject
    Set chk = Me.OLEObjects(CheckBox3.Name)
 
    If runChkBox Then
        runChkBox = False
        Exit Sub
    End If
 
    If Prev(chk) = "NO1" Then
        runChkBox = True
        chk.Object = False
        Exit Sub
    End If
 

End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi, when i tick a checkbox i got the msgbox popup twice
If the msgbox is appearing twice it means that Function Prev is somehow being called twice. Set a breakpoint inside Function Prev so you can interrupt execution and single step to find out why.
 
Upvote 0
Try:
1) Use the 2nd click sub that uses runChkBox
2) in the Function remove the line
VBA Code:
        chk.Object = False
 
Upvote 0
Solution

Forum statistics

Threads
1,223,900
Messages
6,175,276
Members
452,629
Latest member
SahilPolekar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top