how to retrieve the file extension

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

Guest

Hello,
I built a form with a command button that open the FileDialog to retrieve
the path of a database to which I have to connect. Here is the code of the
button:
'Declare a variable as a FileDialog object.
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
Dim quale_path As String
If fd.Show = -1 Then
quale_path = fd.SelectedItems(1)
path_db.Value = quale_path
pathdef = path_db.Value
path_db.Enabled = False
End If

I need to check if the user have selected a .mdb or a .mde file. I have
tried somethjing like

If right(fd.SelectedItems(1),3)<> "mdb" or right(fd.SelectedItems(1),3)<>
"mde" then
msg to user that a wrong file has been selected
else
....
end if

It seems it doesnt' work! I always receive the msg to user that a wrong file
has been selected. There's a better way?

Thanks

Rocco
 
Hello,
I built a form with a command button that open the FileDialog to
retrieve the path of a database to which I have to connect. Here is
the code of the button:
'Declare a variable as a FileDialog object.
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
Dim quale_path As String
If fd.Show = -1 Then
quale_path = fd.SelectedItems(1)
path_db.Value = quale_path
pathdef = path_db.Value
path_db.Enabled = False
End If

I need to check if the user have selected a .mdb or a .mde file. I
have tried somethjing like

If right(fd.SelectedItems(1),3)<> "mdb" or
right(fd.SelectedItems(1),3)<> "mde" then
msg to user that a wrong file has been selected
else
...
end if

It seems it doesnt' work! I always receive the msg to user that a
wrong file has been selected. There's a better way?

Thanks

Rocco

Hi Rocco,

Change the:
If right(.... OR right(...
to:
If right(... AND right(...

That should do it!

HTH
 
yep...sorry.
I have already fixed.
On monday I'm a little more dummy than usual.
Thanks anyway.
Rocco
 
yep...sorry.
I have already fixed.
On monday I'm a little more dummy than usual.
Thanks anyway.
Rocco

You're welcome anyway and thanks for posting back with your success!

8^)
 
Back
Top