My apologies if this has been covered previously. I did a quick search but wasn't sure how to summarize this in a search box.
I have a userform that is used to populate information into a workbook. There are three command buttons - Cancel, Pause, and Next. Cancel clears the userform and ends the macro. Next populates the provided information to the workbook and opens the next userform. Both work exactly as needed. I'm trying to add the Pause button so that users can go out to other Excel documents to gather/copy information (for those wondering, there is no specific file the information might come from so it's not possible to retrieve the information via vba code). I'm also adding a Restart button to the workbook to allow the users to pick up where they left off. Both sets of new code seem to be performing what is expected, but for some reason when the Pause button is clicked the userform closes and then opens again. A second click of the Pause button will close the userform and allow the user to go find the information they need. The code for the Pause button is posted below. It is similar to the code used for the Next button, so I'm stumped as to why the userform reopens when the Pause button is clicked. I'm sure it's something simple that I'm overlooking...any ideas? Thank you in advance!
I have a userform that is used to populate information into a workbook. There are three command buttons - Cancel, Pause, and Next. Cancel clears the userform and ends the macro. Next populates the provided information to the workbook and opens the next userform. Both work exactly as needed. I'm trying to add the Pause button so that users can go out to other Excel documents to gather/copy information (for those wondering, there is no specific file the information might come from so it's not possible to retrieve the information via vba code). I'm also adding a Restart button to the workbook to allow the users to pick up where they left off. Both sets of new code seem to be performing what is expected, but for some reason when the Pause button is clicked the userform closes and then opens again. A second click of the Pause button will close the userform and allow the user to go find the information they need. The code for the Pause button is posted below. It is similar to the code used for the Next button, so I'm stumped as to why the userform reopens when the Pause button is clicked. I'm sure it's something simple that I'm overlooking...any ideas? Thank you in advance!
VBA Code:
Private Sub PauseButton1_Click() 'Clicking "Pause" performs the functions listed below.
Sheets("Form").Unprotect "change" 'Unprotects the "Form" tab to allow answers to populate the cells.
Sheets("Form").Range("C3").Value = Me.txtName.Value 'Adds the user's name to cell C3.
Sheets("Form").Range("C4").Value = Me.txtDate.Value 'Adds the date to cell C4.
Sheets("Form").Range("C5").Value = Me.cboUserLoc.Value 'Adds the user's location to cell C5.
Sheets("Form").Range("C6").Value = Me.txtCustomer.Value 'Adds the customer name to cell C6.
If Me.txtMake.Value = "" Or Me.txtModel.Value = "" Or Me.txtProgCode.Value = "" Then 'If any of the required information fields are blank then...
Sheets("Form").Range("C7").Value = "" '...cell C7 is left blank.
ElseIf Me.txtMake.Value <> "" And Me.txtModel.Value <> "" And Me.txtProgCode.Value <> "" Then 'If all of the required information fields are not blank then...
Sheets("Form").Range("C7").Value = Me.txtMY.Value & " " & Me.txtMake.Value & " " & Me.txtModel.Value & " " & "(" & Me.txtProgCode.Value & ")"
'...adds the vehicle information to cell C7 in "MY Make Model (Program Code)" format.
End If
Sheets("Form").Range("C8").Value = Me.txtComps.Value 'Adds the affected components to cell C8.
Sheets("Form").Range("D10").Value = Me.cboRequest.Value 'Adds the source of the change request to cell D10.
Me.Hide 'Closes the "Request Information" data form.
If Me.cboRequest.Value = Sheets("Data").Range("C1").Value Then 'If the source of the change request is the customer...
Sheets("Form").Range("A11").Value = "What is the customer's Change Number?" 'Adds text to cell A11.
Sheets("Form").Range("A12").Value = "What is the customer's requested implementation date?" 'Adds text to cell A12.
Range("A22:H22").Locked = False
Sheets("Form").Protect Password:="change", DrawingObjects:=False
'From the two lines above the 2nd line protects the "Form" tab with the password "change" while allowing pictures to be inserted into the form. The 1st line allows text to be entered into range A22 through H22 even though the tab is protected.
ElseIf Me.cboRequest.Value = Sheets("Data").Range("C2").Value Then 'If the source of the change request is a supplier...
Sheets("Form").Range("A11:D11").Interior.Color = RGB(192, 192, 192) 'Turns cells A11 through D11 gray.
Sheets("Form").Range("A12").Value = "What date will supplier provide new/modified component(s)?" 'Adds text to cell A12.
Range("A22:H22").Locked = False
Sheets("Form").Protect Password:="change", DrawingObjects:=False
'From the two lines above the 2nd line protects the "Form" tab with the password "change" while allowing pictures to be inserted into the form. The 1st line allows text to be entered into range A22 through H22 even though the tab is protected.
ElseIf Me.cboRequest.Value = Sheets("Data").Range("C3").Value Then 'If the source of the change request is internal...
Sheets("Form").Range("A11:D11").Interior.Color = RGB(192, 192, 192) 'Turns cells A11 through D11 gray.
Sheets("Form").Range("A12").Value = "What is the requested implementation date?" 'Adds text to cell A12.
Range("A22:H22").Locked = False
Sheets("Form").Protect Password:="change", DrawingObjects:=False
'From the two lines above the 2nd line protects the "Form" tab with the password "change" while allowing pictures to be inserted into the form. The 1st line allows text to be entered into range A22 through H22 even though the tab is protected.
ElseIf Me.cboRequest.Value = "" Then 'If the source of the change request is not defined then end the loop.
Range("A22:H22").Locked = False
Sheets("Form").Protect Password:="change", DrawingObjects:=False
'From the two lines above the 2nd line protects the "Form" tab with the password "change" while allowing pictures to be inserted into the form. The 1st line allows text to be entered into range A22 through H22 even though the tab is protected.
End If
End Sub