Excel form button adding message box yes or no option

davidwh000

New Member
Joined
Jul 18, 2010
Messages
24
Hi Everyone

I have a couple of buttons which cause changes to a form and I would like to add a message box to them to allow for the information to be changed or to be rejected. A simple yes no box with yes completing the process and no leaving the data unchanged. I have posted code below for the 2 buttons affected and for one which is working OK but simply exits the program if accepted.

This one is unmodified and does not have the message function

VBA Code:
Private Sub cmdReset_Click()
Dim txt
    For Each txt In Frame2.Controls
        If TypeOf txt Is MSForms.TextBox Then
            txt.Text = ""
        End If
    Next txt
    TxtSearch.Text = ""
    
    Dim i
    For i = 0 To Me.lstDisplay.ListCount - 1
    If Me.lstDisplay.Selected(i) Then Me.lstDisplay.Selected(i) = False
    Next i

End Sub

This one has an experimental message option which does not work.

VBA Code:
Private Sub cmdUpdate_Click()
Dim Answer
Answer = MsgBox("Confirm if you want to update the record?", vbYesNo + vbQuestion, "Update Record")
If Answer = vbYes Then
Cells(updateRow, 1) = TxtAccount.Text
Cells(updateRow, 2) = TxtWebsite.Text
Cells(updateRow, 3) = TxtCategory.Text
Cells(updateRow, 4) = TxtOwner.Text
Cells(updateRow, 5) = TxtLogin.Text
Cells(updateRow, 6) = TxtAccdetail.Text
Cells(updateRow, 7) = TxtPassword.Text
Cells(updateRow, 8) = TxtPin.Text
Cells(updateRow, 9) = TxtEmail.Text
Cells(updateRow, 10) = TxtMemword.Text
Cells(updateRow, 11) = TxtExtra.Text
Cells(updateRow, 12) = TxtNotes.Text
End If

End Sub

This is the Exit one which works OK

Private Sub cmdExit_Click()
iExit = MsgBox("Confirm if you want to exit", vbQuestion + vbYesNo, "Data Entry Form")
If iExit = vbYes Then
Unload Me
End If
End Sub

Would appreciate any help please.
David
 
Last edited by a moderator:

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
In what way doesn't it work?
 
Upvote 0
Do you have a command button called cmdUpdate?
Check that it's not been misspelt.
 
Upvote 0
Do you have a command button called cmdUpdate?
Check that it's not been misspelt.
Yes, I have the command and the update works OK, it is just the message box that oes ot ccome up at all so the confirmation acion does not take place.
Thanks for looking at this.
 
Upvote 0
If you comment out this part of the update code
VBA Code:
Cells(updateRow, 3) = TxtCategory.Text
Cells(updateRow, 4) = TxtOwner.Text
Cells(updateRow, 5) = TxtLogin.Text
Cells(updateRow, 6) = TxtAccdetail.Text
Cells(updateRow, 7) = TxtPassword.Text
Cells(updateRow, 8) = TxtPin.Text
Cells(updateRow, 9) = TxtEmail.Text
Cells(updateRow, 10) = TxtMemword.Text
Cells(updateRow, 11) = TxtExtra.Text
Cells(updateRow, 12) = TxtNotes.Text
and then run the code, does it just update columns A & B?
 
Upvote 0
If you comment out this part of the update code
VBA Code:
Cells(updateRow, 3) = TxtCategory.Text
Cells(updateRow, 4) = TxtOwner.Text
Cells(updateRow, 5) = TxtLogin.Text
Cells(updateRow, 6) = TxtAccdetail.Text
Cells(updateRow, 7) = TxtPassword.Text
Cells(updateRow, 8) = TxtPin.Text
Cells(updateRow, 9) = TxtEmail.Text
Cells(updateRow, 10) = TxtMemword.Text
Cells(updateRow, 11) = TxtExtra.Text
Cells(updateRow, 12) = TxtNotes.Text
and then run the code, does it just update columns A & B?
Yes, but in the actual file the update works OK, updating all 12 columns. Is there anywhere that I can post the sample spreadsheet as I am really close to it all working but still have a few small problems. I think I have solved the message box issue.
 
Upvote 0
If you have got the msgbox working, but now have other questions, then you will need to start a new thread.
 
Upvote 0

Forum statistics

Threads
1,214,656
Messages
6,120,762
Members
448,991
Latest member
Hanakoro

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