Morning Everyone ,
How can I tell when a user selects a file in a common dialog box . I have a CDB to let the user browsw to a file , I want to know when he has selected it and pressed "open"
Thnks
[]P
Printable View
Morning Everyone ,
How can I tell when a user selects a file in a common dialog box . I have a CDB to let the user browsw to a file , I want to know when he has selected it and pressed "open"
Thnks
[]P
Your code will stop at
until the user clicks Open or Cancel. So:Code:CommonDialog1.ShowOpen
The message box will come up after the user has click Open or Cancel.Code:CommonDialog1.ShowOpen
Msgbox "selected"
Sunny
Here is some more about Common Dialogue box. Following is copied from code which worked.Some of the above is specific to my application, but it should give you some ideas.Code:Private Sub mnuFileOpen_Click()
'cdlOFNCreatePrompt &H2000 File should not exist'
'cdlOFNFileMustExist &H1000'
'cdlOFNOverwritePrompt &H2'
'cdlOFNPathMustExist &H800'
'cdlOFNLongNames &H200000'
dlogCommon.Flags = &H201800 'Long Names; File & Path must exist'
dlogCommon.CancelError = True
dlogCommon.DialogTitle = "Gravity: Read File"
dlogCommon.FileName = GrvtyFile
dlogCommon.InitDir = GrvtyDirectory
dlogCommon.Filter = "Gravity Files(*.grv)|*.grv|All Files(*.*)|*.*"
On Error GoTo BadOpen
dlogCommon.ShowOpen
'Fall through here if User does not cancel/close'
GrvtyFileName = dlogCommon.FileName
Call BodyGettor(GrvtyFileName)
cboxBodyName.SetFocus
Exit Sub
BadOpen:
'Ignore: User changed him mind about opening file'
cboxBodyName.SetFocus
End Sub
You can also just put
CommonDialog1.ShowOpen
FileName = CommonDialog1.FileName
if FileName = "" then exit sub
If the user clicks cancel, the subroutine won't continue.
You must have CancelError set to true and error handling as well so that if the user presses cancel, you won't get any error.Quote:
Originally posted by olaf_001
You can also just put
CommonDialog1.ShowOpen
FileName = CommonDialog1.FileName
if FileName = "" then exit sub
If the user clicks cancel, the subroutine won't continue.
'On Error Resume Next
'CommonDialog.CancelError = True
Thnks Guys , I was trying to figure out WHEN I could get the the stats of the File selected like size and type . Now I know :)
Thanks again ,
[]P