Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,590
- Office Version
- 365
- 2016
- Platform
- Windows
Please consider this code,
In our example, lets assume no_rw = 21. If no_rw > 0 then open the userform called 'msg_raw_data_in_file'.
The userform opens, and has a command button called "CANCEL". If the user selects this option, he is returned to a default state of the application, which consists of activating the home worksheet and opening the preliminary application's userform (uf1_create-wo1)
Here is the cancel commandbutton code"
Here is my problem ...
When the above code is executed, the home worksheet is activated, and the userform initiatizes and becomes visible. But after that, the code returns to procedure 'create1_click' at the line highlighted in blue. The line in red unfortunately closes uf1_create_wo1, which I don't want.
What can I do to prevent the userform from closing?
Rich (BB code):
Private Sub create1_Click()
Dim strFilename As String
Dim ws_vh As Worksheet
Dim no_rw As Long
Dim ui1 As VbMsgBoxResult
Dim oFS As Object
Dim uimsg As Long
Dim fw As Long
Application.ScreenUpdating = False
strFilename = "H:\PWS\Parks\Parks Operations\Sports\Sports15\CLASS_DUMP\schedule.csv"
Set oFS = CreateObject("Scripting.FileSystemObject")
Set ws_vh = Workbooks("Sports17.xlsm").Worksheets("VAR_HOLD")
f_name = "schedule.csv"
If CheckFileIsOpen(f_name) = True Then
Debug.Print "schedule.csv is open and hidden"
Workbooks(f_name).Close False
End If
Debug.Print "schedule.csv is not open. It will be opened now."
Workbooks.Open Filename:=strFilename 'open schedule.csv
Workbooks("schedule.csv").Windows(1).Visible = False 'hide it
With Workbooks("schedule.csv").Worksheets("schedule")
no_rw = WorksheetFunction.CountIf(.Range("M:M"), ws_vh.Range("B17")) 'determine number of rows of raw data that match the selected dates
ws_vh.Range("F17") = no_rw
End With
Application.ScreenUpdating = True
'If rows of data are found for the selected date
If no_rw > 0 Then
msg_raw_data_in_file.Show
Else
msg_data_not_in_schedule.Show
End If
End Sub
In our example, lets assume no_rw = 21. If no_rw > 0 then open the userform called 'msg_raw_data_in_file'.
The userform opens, and has a command button called "CANCEL". If the user selects this option, he is returned to a default state of the application, which consists of activating the home worksheet and opening the preliminary application's userform (uf1_create-wo1)
Here is the cancel commandbutton code"
Rich (BB code):
Private Sub CommandButton3_Click() 'CANCEL
Workbooks("schedule.csv").Close savechanges:=False
Application.ScreenUpdating = True
Unload msg_raw_data_in_file
Unload uf1_create_wo1
uf1_create_wo1.Show
Workbooks("sports17.xlsm").Worksheets("FRONT").Activate
End Sub
Here is my problem ...
When the above code is executed, the home worksheet is activated, and the userform initiatizes and becomes visible. But after that, the code returns to procedure 'create1_click' at the line highlighted in blue. The line in red unfortunately closes uf1_create_wo1, which I don't want.
What can I do to prevent the userform from closing?