Common dialog cancel property

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form that uses a common dialog control to select a file for
importing to the database. If the user clicks the Cancel button it causes an
error, so I tried to catch this with a simple if statement:

If dlg.Cancel = True Then
Exit Sub
End If

However, this gives me a different error -- an invalid reference to the
property Cancel. How can I simply test for Cancel before beginning my file
import routine?
 
I don't know which control you are using for sure, but most dialogs will
return either Null or a zero length string ("") if the user cancels. I would
run a test to capture what it is returning, then modify my code to check for
that value.
 
Hi Mike,

Public Function StringInput (strPrompt as String, strTitle as String,
strDefault as String)
Dim strInput As String
strInput = InputBox(strPrompt, strTitle, strDefault)
If StrPtr(strInput) = 0 Then
MsgBox "Cancel was pressed"
Else
If Len(strInput) = 0 Then
MsgBox "OK pressed but nothing entered."
Else
MsgBox "OK pressed: value= " & strInput
End If
End If
End Function

This how I look for a cancel response from an input box, would have
thought that it was transferable.

Good luck

Nick
 
Hi Mike,

Public Function StringInput (strPrompt as String, strTitle as String,
strDefault as String)
Dim strInput As String
strInput = InputBox(strPrompt, strTitle, strDefault)
If StrPtr(strInput) = 0 Then
MsgBox "Cancel was pressed"
Else
If Len(strInput) = 0 Then
MsgBox "OK pressed but nothing entered."
Else
MsgBox "OK pressed: value= " & strInput
End If
End If
End Function

This how I look for a cancel response from an input box, would have
thought that it was transferable.

Good luck

Nick
 
Back
Top