File dialog - stopped working.

Bosch

Registered User.
Local time
Today, 14:02
Joined
May 13, 2005
Messages
89
Hello...

This should be an easy one for many of you..

I have the following to code to let the user select a file..
It worked before but suddenly stopped working...I remember adding some reference but I dont remember exactly the name of the reference..

After I did this, I converted the database from 2000 - 2002/2003 ..back and forth...I did not change/remove any references.

I have access 2003 but my database is in 2000 format because my teammates have 2000.

Thanks in advance for the help.

-------------------------------------------
Dim fDialog As Office.FileDialog
Dim varFile As Variant

' Set up the File Dialog.
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)

With fDialog

' Allow user to make multiple selections in dialog box
.AllowMultiSelect = False

' Set the title of the dialog box.
.Title = "Please select a file"

' Clear out the current filters, and add our own.
'.Filters.Clear
' .Filters.Add "All Files", "*.*"
'.Filters.Add "Access Projects", "*.HTM"
'.Filters.Add "Access Projects", "*.HTML"
'.Filters.Add "Access Projects", "*.DOC"
'.Filters.Add "Access Databases", "*.VST"
'.Filters.Add "Access Databases", "*.VSD"
'.Filters.Add "Access Databases", "*.TXT"
'.Filters.Add "Access Databases", "*.MDB"
'.Filters.Add "Access Projects", "*.XLS"


' Show the dialog box. If the .Show method returns True, the
' user picked at least one file. If the .Show method returns
' False, the user clicked Cancel.
If .Show = True Then

'Loop through each file selected and add it to our list box.
For Each varFile In .SelectedItems
DocsPath_TB.Value = varFile
Next

End If
End With

End Sub
---------------------
 
I am getting Compile Error
User defined type not defined.
 
Your problem is one of many reasons not to use an activex control. I do anything to avoid using objects that require references.

Check out my Browse [Find a directory or file] sample to see how easy you can use an API to allow the user to browse a directory and/or browse and select a file.
 
ghudson said:
Your problem is one of many reasons not to use an activex control. I do anything to avoid using objects that require references.

Check out my Browse [Find a directory or file] sample to see how easy you can use an API to allow the user to browse a directory and/or browse and select a file.


Can you repost please.. seems like all the links are gone.

Thanks
 
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

Private Type OPENFILENAME
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 Sub Command1_Click()

DoCmd.SetWarnings (False)
Dim OpenFile As OPENFILENAME
Dim lReturn As Long
Dim sFilter As String
OpenFile.lStructSize = Len(OpenFile)
OpenFile.hwndOwner = Me.Hwnd
OpenFile.hInstance = 0
sFilter = "CSV Files(*.csv)" & Chr(0) & "*.csv" & 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.lpstrTitle = "Use the Comdlg API not the OCX"
OpenFile.flags = 0
lReturn = GetOpenFileName(OpenFile)
If lReturn = 0 Then

Exit Sub
Else
End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom