Common dialog cancel property

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?
 
G

Guest

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.
 
N

Nick 'The database Guy'

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
 
N

Nick 'The database Guy'

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top