VBA OR function help please

Mikeymike_W

Board Regular
Joined
Feb 25, 2016
Messages
171
Hi there,

I'm rying to set a condition on a user form so that the user needs to close a textbox before the open another. The textbox is opened via a command button.
I have never used the "OR" function before so had a look online. The code I have just opens up the msgbox regardless f whether or not other textboxes are open and i'm not sure where to go from here.

In the code below i'm trying to say that if TBPsychology1 is visible then just make it invisible, however if it is invisible check to see if other textboxes are visible, if they are then prompt the user to close them alternatively if no other textbox is visible then just make TBPsychology1 visible.

I hope that makes sense.

Thanks in advance for your help!

VBA Code:
Private Sub CBPsychology_Click()

If TBPsychology1.Visible = False Then
    If TBPsychology2.Visible = True Or TBPsychology3.Visible = True Or TBPsychology.Visible = True Then
MsgBox "Please close any open dialogue boxes", , "Close Dialogue Boxes"
Exit Sub
Else
TBPsychology1.Visible = True
End If
End If

If TBPsychology1.Visible = True Then
TBPsychology1.Visible = False
End If    
    
End Sub
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Are the textboxes actually hidden, or just disabled?
 
Upvote 0
In that case if all 4 of those textboxes are hidden, you shouldn't get the message box.
 
Upvote 0
Got it sorted, i dont know why but the first IF statement was causing the issue so just removed it and reorganised the code.
Thanks for your help though.

VBA Code:
If TBPsychology2.Visible = True Or TBPsychology3.Visible = True Then
MsgBox "Please close any open dialogue boxes", , "Close Dialogue Boxes"
Exit Sub
End If

If TBPsychology1.Visible = True Then
TBPsychology1.Visible = False
Else
TBPsychology1.Visible = True
End If
 
Upvote 0

Forum statistics

Threads
1,215,020
Messages
6,122,712
Members
449,093
Latest member
Mnur

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