I have seen several samples of code that shows the message box being used to display a 'Yes', 'No' responce after the Yes, No buttons within the MsgBox were clicked. My question, can the [Yes, No] buttons be programed to complete/preform an independent action when clicked? Meaning, I click 'Yes' a partictular action happens, or I click 'No' and a partictular action happens, such as [if,them,ElseIf]. I am trying to get them to work independly and it seems that I can only get one or the other button to work as I want it to but the other stops working. Put another way, MsgBox has already given the answere to a previous action now what do you want to do, 'Yes' this, 'No' that, with no further conformations/responses needed. FYI, I am using "ktMsgBoxAddin.xla" addin, if it makes any difference.
Thanks for your help/suggestions in advance.
Originally Posted by Wingnut_2
I thing what you're getting at is using the result of the Yes/No message box to perform one of two mutually independent procedures. Try the following code. If it's not what you're seeking, please post back.
Sub MsgBoxTest() Dim iAnswer As Integer iAnswer = MsgBox("Choose Yes or No", vbYesNo) If iAnswer = 7 Then MsgBox "No" 'do this code Else MsgBox "Yes" 'do this other code End If End Sub In the Yes/No message box the No button returns the value 7, whilst the Yes button returns 6. HTH
Another 2 ways of coding it is
The 2nd version is great way to code if testing the same item for multiple options
Sub MsgBoxTest1() If MsgBox("Choose Yes or No", vbYesNo) = vbNo Then MsgBox "No" 'do this code Else MsgBox "Yes" 'do this other code End If End SubSub MsgBoxTest2() Select Case MsgBox("Choose Yes or No", vbYesNo) = vbNo Case vbNo MsgBox "No" 'do this code Case vbYes MsgBox "Yes" 'do this other code End Select End Sub
Please Read Forum Rules Before Posting
Wrap VBA code by selecting the code and clicking the # icon or Read This
How To Cross Post politely
Top Excel links for beginners to Experts
If you are pleased with a member's answer then use the Scales icon to rate it
If my reply has assistedor failed to assist you
I welcome your Feedback.
First of all thanks for your responses.
The thing is I am already at this point and unable to process 'Yes' (ThisAction), 'No' (ThisAction) (End). And then again I may not be following my own code and have gotten myself into the perverbial corner. If you need to see what I am trying to do let me know and I'll post the code. It will take a bit to make sure I post it correctly as I am kinda new at this.
Maybe this will help. When I click the 'Yes' button I want TextBox1 "Not" to clear. When I click the "No" button I want Textbox1 "to" clear. I know this, again, is kinda vague without the rest of the code.
I know 101 ways it won't work but not the one that will work. Than, again, maybe it won't!
Regards
Wingnut
Again thanks for the responses.
Here is what I am trying to do:
"Search" clicked "Please inter title, etc.
"Is title in the data base" 'Yes'
"If 'Yes', done.
"If 'No', do you want it put into the data base?
"If 'Yes', MsgBox closes and the new "Title" remains in TextBox1.
"If 'No', MsgBox closes and the typed "Title" is cleared from TextBox1.
Private Sub CommandButton10_Click() ' ' Search for movie title. ' Application.ScreenUpdating = False ThisWorkBook.Activate TextBox1.SetFocus Dim Prompt As kt_MsgBoxPromptType Dim c If Me.TextBox1.Text = "" Then Call ktMsgBoxPromptTypeInit(Prompt) With Prompt .Message(1) = "* Please Type A Movie Title In The 'Input' Box! *" .FName(1) = "Georgia" .FSize(1) = 9 .FBold(1) = True .FColor(1) = vbRed ktMsgBoxEx Prompt, vbOKOnly + vbExclamation, " You Forgot To Type A Movie Title!", BackColor:=&HF4F4F4 End With Exit Sub End If With Worksheets("Sheet1").Range("B2:B5040") Set c = Cells.Find(Me.TextBox1.value, LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False) If Not c Is Nothing Then Call ktMsgBoxPromptTypeInit(Prompt) With Prompt .Message(1) = "* Title Found! *" .FName(1) = "Georgia" .FSize(1) = 9 .FBold(1) = True .FColor(1) = vbRed ktMsgBoxEx Prompt, vbOKOnly, " Good News!", IconFile:="c:\Hand_256.ico", BackColor:=&HF4F4F4 End With Else Call ktMsgBoxPromptTypeInit(Prompt) With Prompt .Message(2) = " * Title Not Found! *" .Message(3) = "*** Would You Like To Add This 'Title'? ***" .FName(2) = "Georgia" .FSize(2) = 11 .FBold(2) = True .FColor(2) = vbRed .FName(3) = "Georgia" .FSize(3) = 8 .FBold(3) = True .FColor(3) = vbBlack ktMsgBoxEx Prompt, vbYesNo, " Darn, don't have this one!", IconFile:="c:\Hand_256_TD.ico", BackColor:=&HF4F4F4 If vbYes Then 'Works as long as I rem out 'If vbNo Then', meaning the typed title remains in MsgBox1. Me.TextBox1.Text = Me.TextBox1.Text End If End With ' If vbNo Then 'If I don' rem this out the tite that has been entered into MsgBox1 clears even if "Yes" has been clicked. ' Me.TextBox1.Text = "" End If End With End Sub
If I understand you code correctly you are calling another macro that displays a message box withIf this is correct you do not appear to have a meeans of identifying what the users response to that messgaebox is.Call ktMsgBoxPromptTypeInit(Prompt)
To get the users reponse you need to set a variable to capture that response & then test that variable
Please Read Forum Rules Before Posting
Wrap VBA code by selecting the code and clicking the # icon or Read This
How To Cross Post politely
Top Excel links for beginners to Experts
If you are pleased with a member's answer then use the Scales icon to rate it
If my reply has assistedor failed to assist you
I welcome your Feedback.
I finally found a work-around that gets the job done.
TextBox1.Text = "" Exit Sub End If Call ktMsgBoxPromptTypeInit(Prompt) With Prompt .Message(1) = "* Title Not Found! *" .FName(1) = "Georgia" .FSize(1) = 11 .FBold(1) = True .FColor(1) = vbRed ktMsgBoxEX Prompt, vbOKOnly, " Darn, don't have this one!", IconFile:="c:\Documents and Settings\Bob\My Documents\MovieWorkbook\Hand_256_TD.ico", BackColor:=&HF4F4F4 End With Call ktMsgBoxPromptTypeInit(Prompt) With Prompt Resp = ktMsgBox("** Would You Like To Save This 'Title'? **", vbYesNo + vbQuestion, Title:=" Save 'Title'? ", FontName:="Georgia", FontSize:=11, BackColor:=&HF4F4F4) If vbYes Then TextBox1.Text = TextBox1.Text End If If (Resp = vbNo) Then TextBox1.Text = "" End If End With End With End Sub
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks