Excel form button adding message box yes or no option

davidwh000

New Member
Joined
Jul 18, 2010
Messages
21
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:

Some videos you may like

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,757
Office Version
  1. 365
Platform
  1. Windows
In what way doesn't it work?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,757
Office Version
  1. 365
Platform
  1. Windows
Do you have a command button called cmdUpdate?
Check that it's not been misspelt.
 

davidwh000

New Member
Joined
Jul 18, 2010
Messages
21

ADVERTISEMENT

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.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,757
Office Version
  1. 365
Platform
  1. Windows
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?
 

davidwh000

New Member
Joined
Jul 18, 2010
Messages
21

ADVERTISEMENT

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.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,757
Office Version
  1. 365
Platform
  1. Windows
If you have got the msgbox working, but now have other questions, then you will need to start a new thread.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,757
Office Version
  1. 365
Platform
  1. Windows
You're welcome.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,246
Messages
5,595,044
Members
413,963
Latest member
teggl97

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
Top