myall_blues
Well-known Member
- Joined
- Nov 26, 2015
- Messages
- 670
- Office Version
- 365
- Platform
- Windows
Hi
I have an issue with a Sub that calls a userform - after I click OK on the form it does not continue with the Sub but rather just stops. Debugging seems to indicate that is stays at the 'show' statement in the sub. I have this same code in another application and it works perfectly, and I have been unable to figure out the difference.
Here is my Sub calling code:
And here is the code in my userform:
Any thoughts gratefully appreciated. I've been looking at this for hours.
I have an issue with a Sub that calls a userform - after I click OK on the form it does not continue with the Sub but rather just stops. Debugging seems to indicate that is stays at the 'show' statement in the sub. I have this same code in another application and it works perfectly, and I have been unable to figure out the difference.
Here is my Sub calling code:
VBA Code:
Private Sub ImportData()
'
'
' Get input filename from form
'
Dim frm As New frmGetFile
With frm
.Show ' <= Never goes past this line
If Not .TypeCancelled Then
'
' Do some further processing
'
End If
'
' Clean up
'
Unload frm
Set frm = Nothing
End With
End Sub
And here is the code in my userform:
VBA Code:
Option Explicit
Private cancelled As Boolean
Public Property Get TypeCancelled() As Boolean
TypeCancelled = cancelled
End Property
Private Sub cmdGetFileCancel_Click()
'
' Cancel button - unload form
'
OnCancel
End Sub
Private Sub OnCancel()
Hide
cancelled = True
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = VbQueryClose.vbFormControlMenu Then
Cancel = True
OnCancel
End If
End Sub
Private Sub cmdGetFileOK_Click()
'
Dim r As Integer
Dim wksNewSheet As Excel.Worksheet
Dim TempVal As String, ErrorString As String
'
' Check that all mandatory values have been completed
'
With Me
If Len(Label5.Caption) = 0 Or Len(ComboBox1.Value) = 0 Then
ErrorString = ErrorString + "Please complete all mandatory fields (marked by *)." & vbNewLine
MsgBox ErrorString, vbCritical, "Values Missing"
OnCancel
Exit Sub
' Else
' cancelled = False
End If
End With
If Not cancelled Then
'
' Do some stuff
'
End If
End Sub
Any thoughts gratefully appreciated. I've been looking at this for hours.