ofn filter for text not working

tweetyksc

Registered User.
Local time
Today, 19:32
Joined
Aug 23, 2001
Messages
87
I had used some code found here a while ago to utilize with prompting a user to choose the filename to import. I've altered it with some things to work for what I need, and it works fine, except the filter for text doesn't work - all files show, even though the text ["text files (*.txt)] set for the filter appears in the "files of type" box, it doesn't filter the list. What am I missing?

Here is the code that defines and runs the open dialog box.
_________________________
Private Type FILENAME
'type and fx declaration for use with importing text file
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type

Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (pOpenfilename As FILENAME) As Long
'-----------------------------------------------

Private Sub cmdImportData_Click()
On Error GoTo Err_cmdImportData_Click

Dim strtablename As String
Dim strqueryname As String

Select Case optImportData
Case 1
strtablename = "BPMultilevelCSR"
strqueryname = "qryDeleteBPs"
Case 2
strtablename = "ReorderAnalysis"
strqueryname = "qryDeleteItems"
End Select

If MsgBox("Are you sure you want to import new " & strtablename & " data?", vbYesNo, "Import " & strtablename) = vbNo Then
Exit Sub

Else
'import the file
Dim ofn As FILENAME
Dim b

b = "Select " & strtablename & " text File to import"
ofn.lStructSize = Len(ofn)
ofn.hwndOwner = Form.Hwnd
ofn.lpstrFilter = "Text Files (*.txt)"
ofn.lpstrFile = Space$(254)
ofn.nMaxFile = 255
ofn.lpstrFileTitle = Space$(254)
ofn.nMaxFileTitle = 255
ofn.lpstrInitialDir = CurDir
ofn.lpstrTitle = b
ofn.flags = 0

Dim a
a = GetOpenFileName(ofn)
If (a) Then
DoCmd.TransferText acImportDelim, strtablename, strtablename, ofn.lpstrFile
MsgBox "Import Complete! Data has been added to the " & strtablename & " table", , strtablename & " Import"
Else
MsgBox "Import Canceled", , strtablename & " Import"
Exit Sub
End If
End If
 

Users who are viewing this thread

Back
Top Bottom