469,167 Members | 2,108 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,167 developers. It's quick & easy.

File selection problem

1
This script below is having problems with allow the selestion of *.mdb files off the network. Can anyone see the problem with the code?
[code]

Function ImportFile(strform As Form) As Boolean
Dim OpenFile As OPENFILENAME
Dim lReturn As Long
Dim sFilter As String
Dim ChosenFileName As String

ImportFile = True

OpenFile.lStructSize = Len(OpenFile)
OpenFile.hwndOwner = strform.Hwnd
sFilter = "Microsoft Access (*.mdb)" & Chr(0) & "*.mdb" & Chr(0) & _
"All Files (*.*)" & Chr(0) & "*.*" & Chr(0)
' "Text (*.TXT)" & Chr(0) & "*.TXT" & Chr(0) &
OpenFile.lpstrFilter = sFilter
OpenFile.nFilterIndex = 1
OpenFile.lpstrFile = String(257, 0)
OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
OpenFile.lpstrFileTitle = OpenFile.lpstrFile
OpenFile.nMaxFileTitle = OpenFile.nMaxFile
OpenFile.lpstrInitialDir = "C:\"
OpenFile.lpstrTitle = "Select an Access Database"
OpenFile.flags = 0
lReturn = GetOpenFileName(OpenFile)
ChosenFileName = Left(OpenFile.lpstrFile, InStr(OpenFile.lpstrFile, ".") + 3)
If lReturn = 0 Then
MsgBox "A file was not selected!", vbInformation, "Select a File"
ImportFile = False
ElseIf LCase(Right(ChosenFileName, 4)) = ".mdb" Then
LinkTables (ChosenFileName)
Else
MsgBox "File must be an Access Database (*.mdb)!", vbOKOnly, "Error"
ImportFile = False
End If
End Function
Aug 29 '08 #1
2 1003
QVeen72
1,445 Expert 1GB
Hi,

Filter string should be given like this: (with a Single Pipe Character)

Expand|Select|Wrap|Line Numbers
  1. CommDlg.Filter = "Access Database (*.mdb)|*.mdb"
  2.  
REgards
Veena
Aug 30 '08 #2
Hello

Your problem is the sFilter line. Try this

Dim sFilter As String

sFilter = "Microsoft Access (*.mdb)|*.mdb"
sFilter += "|All Files (*.*)|*.*"

Me.OpenFileDialog1.Filter = sFilter
Me.OpenFileDialog1.ShowDialog()


To separate files type you need to use the pipe character. << | >>
Aug 31 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by John Pastrovick | last post: by
2 posts views Thread by clockworx05 | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.