Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old August 29th, 2008, 02:54 PM
Newbie
 
Join Date: Aug 2008
Posts: 1
Default File selection problem

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
Reply
  #2  
Old August 30th, 2008, 07:11 AM
QVeen72's Avatar
Moderator
 
Join Date: Oct 2006
Location: Bangalore
Posts: 1,292
Default

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
Reply
  #3  
Old August 31st, 2008, 03:56 PM
Member
 
Join Date: Aug 2008
Location: Sao Paulo - Brasil
Age: 52
Posts: 75
Default

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. << | >>
Reply
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles