Link to home
Start Free TrialLog in
Avatar of ADawn
ADawn

asked on

Filter files with these extensions (File Dialog Box)

Hi again,

VB6 (sp4) ADO

I have two concerns. I want to display all files with these extensions: *.htm and *html in my file dialog box, and I want to check to see if the proper file extension was selected before I save its location to the Windows registry. Thanks for your help (as always).

With frmOptions.cd_Options
      .DialogTitle = "Connect to application's back-end database."
      .InitDir = "C:\DS3VB6\DS3_DATA\"
      .FileName = "" 'App_BackEndDBName
      .Filter = "Access (*.mdb)| *.mdb"
      .CancelError = True 'Causes an error if user clicks on cancel
      .ShowOpen
    End With
'Remember that the file names are case sensitive
    Do While UCase(Right(Trim(frmOptions.cd_Options.FileName), Len("DS3DATA.MDB"))) <> "DS3DATA.MDB"
      MsgBox "You are trying to link to the wrong file.", vbCritical, App.Title
      frmOptions.cd_Options.ShowOpen
    Loop
      App_InventoryPath = Trim(frmOptions.cd_Options.FileName)
      frmOptions.txtInventoryPath = App_InventoryPath
    'Save the Database location
    SaveSetting App.Title, "App_Elements", "InventoryPath_DB", App_InventoryPath


-ADawn
Avatar of JonFish85
JonFish85

To limit the users to HTML files:
.Filter = "HTML Files (*.HTML, *.HTM)|*.html;*.htm"

To check the type (place this right after the line of code to show the dialog:
If Right$(UCase(CommonDialog1.FileName), 4) <> "HTML" Or Right$(UCase(CommonDialog1.FileName), 3) <> "HTM" Then
  MsgBox "Invalid Selection!", vbCritical, "Error"
  Exit Sub
Else
  'Write to registry
End If
er, change the ...<> "HTML" Or Right$... to ...<> "HTML" And Right$...
ASKER CERTIFIED SOLUTION
Avatar of TravisHall
TravisHall

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial