tags:

views:

28

answers:

2

USING VB 6

My code.

CommonDialog1.DialogTitle = "Open File"
CommonDialog1.Filter = "Database (1.mdb) |1.mdb"
CommonDialog1.FilterIndex = 1
CommonDialog1.Flags = cdlOFNFileMustExist + cdlOFNHideReadOnly
CommonDialog1.CancelError = True
On Error Resume Next
CommonDialog1.ShowOpen
If Err Then
    MsgBox "Select Database"
    Exit Sub
End If

I am using open dialog in my project. When I run the project I selected the file from the remote system.

Suppose if the remote system was not available, Next time when I select the open dialog, the open dialog should display the c Drive

Now it is displaying my Project folder, it should display the c Drive

How to write a code for this condition?

Need VB6 code Help.

A: 

The answer your looking for is on the VBCity site http://vbcity.com/forums/faq.asp?fid=9&cat=Common+Dialog&#TID82667 The Code example there allows you to do exactly what your asking for.

Hope that Helps!

Robert French
+1  A: 

This will solve what you are asking:

To get FileSystemObject, you must add a reference in your project to 'Microsoft Scripting Runtime'.

Dim fs As New FileSystemObject
Dim currentDir As String
currentDir = fs.GetParentFolderName(CommonDialog1.FileName)
If fs.FolderExists(currentDir) Then
    CommonDialog1.InitDir = currentDir
Else
    CommonDialog1.FileName = ""
    CommonDialog1.InitDir = "C:\"
End If

EDIT:
You must also set CommonDialog1.FileName = ""

awe