Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Dialog

Status
Not open for further replies.

ajolson1964

Programmer
Mar 25, 2008
31
US
I am having a heck of a time getting fileDiolog box to open so a user can
select a file to import into an access tbl. I am using the following code
but get a compile error stating that ahtAddfilterItem "Sub or Function Not
defined"

Dim strFilter As String
Dim strInputFileName As String

strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.XLS)", "*.XLS")
strInputFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select an input file...", _
Flags:=ahtOFN_HIDEREADONLY)
'strInputFileName contains the full path to whatever file was selected.
Using C:\Test" as the path am I way off base for what I want to do?

In a prefect world the user would select a file from that folder( excel
file) and it would load into a table. What code would I use to achive this?

thanks
Andy


 
I would say that you'd be missing the declarations for the API calls you're trying to make. Here's a slightly different (and proably easier to understand) way to do it using CreateObject.
Code:
Const cdlOFNPathMustExist = &H800
Const cdlOFNOverwritePrompt = &H2
Const cdlOFNHideReadOnly = &H4

Dim objFileDialog As Object

On Error GoTo ErrHan:

Set objFileDialog = CreateObject("MSComDlg.CommonDialog")

With objFileDialog

    .CancelError = True
    .Flags = cdlOFNPathMustExist Or cdlOFNOverwritePrompt Or cdlOFNHideReadOnly 
    .DialogTitle = "Please select an input file..."
    .DefaultExt = ".xls"
    .Filter = "Microsoft Excel Workbook (*.xls)|*.xls"
    .ShowOpen
    MsgBox .filename

End With

'Exit Sub/Function here

ErrHan:

If Err.Number = 32755 Then ' user cancelled open file dialog
    Exit Function
Else
    ' normal error handling
End If
If you need anything clearing up with the above code just post back.

Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.

 
How are ya ajolson1964 . . .

You can also use the [blue]GetFilenameFromBrowse[/blue] API.

See my post here thread702-1289131

[blue]Your Thoughts? . . .[/blue]

BTW ... [blue]Welcome to Tek-Tips[/blue]. Be sure to have a look at one of the links at the bottom of my post.

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top