Help with Dialog

K

Kou Vang

I am using the "How to use the common dialog API in a database in access
2003" example in the KB for my project. I have Access 2000, not sure if
that's the problem, but I can't get the filename to come up in my listbox?
It specifies a textbox, but does it make a difference? Thanks.

http://support.microsoft.com/kb/888695/en-us

Private Sub CmdGetXls_Click()

Me!LstXlsFiles = GetFiles(Me)

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

Function GetFiles(TubeImport As Form) As String
Dim OpenFile As OPENFILENAME
Dim lReturn As Long
Dim sFilter As String
Dim sTmp As String
Dim sPath As String
Dim I As Integer

OpenFile.lStructSize = Len(OpenFile)
OpenFile.hwndOwner = TubeImport.Hwnd
sFilter = "Excel Files (*.xls)" & Chr(0) & "*.xls" & 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 = "n:\trafmon\vc_data\newtube"
OpenFile.lpstrTitle = "Select a file using the Common Dialog DLL"
OpenFile.flags = 0
lReturn = GetOpenFileName(OpenFile)
'Debug.Print OpenFile.lpstrFile

End Function

End Sub
 
K

Kou Vang

I tried that, but I get an error with the "ahtAddFilterItem", saying sub or
function not defined? What does the prefix "aht" stand for anyways? Do I
need to make a reference?
 
D

Douglas J Steele

aht is the prefix Ken and his co-authors used to prefix all of their code in
the Access Developer's Handbook.

If you're getting the sub or function not defined message, you must not have
copied everything from that page. Copy everything between Code Start and
Code End.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top