In VB6, if I press the Cancel
button on an Open File
dialog box, my filename is still added into my listbox.
For example:
Private Sub btnImportImage_Click()
DailogOpenFile.ShowOpen
If Trim$(txtEmailAttachment.Text) = "" Then
txtEmailAttachment.Text = DailogOpenFile.FileName
Else
txtEmailAttachment.Text = txtEmailAttachment.Text & ";" & DailogOpenFile.FileName
End If
End Sub
It looks like you're using the CommonDialog
control? If so, you need to set the CancelError
property to True
and then test for an error afterwards. For example:
Private Sub btnImportImage_Click()
DailogOpenFile.CancelError = True
On Error Resume Next
DailogOpenFile.ShowOpen
If Err.Number = &H7FF3 Then
' Cancel clicked
Else
End If
...
End Sub
Of course, you can also jump to an error handler:
Private Sub btnImportImage_Click()
DailogOpenFile.CancelError = True
On Error GoTo MyErrorHandler
DailogOpenFile.ShowOpen
...
MyErrorHandler:
' Cancel was clicked or some other error occurred
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With