Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 13th, 2006, 08:09 AM
Registered User
 
Join Date: Mar 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Open the "Open File" dialogue box

I want to be able to open a txt file by clicking on a button on a form. This should display the Open File dialogue box.

This is quite simple in Excel, as it's just Application.GetOpenFilename but not the case in Acess 2000.

Some of the information we wish to store in a database is obtainable from text files, so it makes sense to scan through the text file for certain rows of information.

Thanks in Advance
Reply With Quote
  #2 (permalink)  
Old March 13th, 2006, 03:50 PM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

You want the user to browse for the file? Or do you want to open the file on NotePad? How would this work?


mmcdonal
Reply With Quote
  #3 (permalink)  
Old March 14th, 2006, 04:28 AM
Registered User
 
Join Date: Mar 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Locate the file, return the filename and path and then open the file for input to locate the required data and copy it into defined fields.
I have achieved all this, but have used a crude input box to ask for a filename in one location only.

Reply With Quote
  #4 (permalink)  
Old March 14th, 2006, 11:06 AM
Authorized User
 
Join Date: Mar 2006
Location: Bratislava, , Slovakia.
Posts: 80
Thanks: 0
Thanked 0 Times in 0 Posts
Default

use Microsoft Common Dialog Control ActiveX, or search web for implementation of functions of comdlg32.dll for VB.
Try www.pscode.com/vb, or www.freevbcode.com

Peko

Reply With Quote
  #5 (permalink)  
Old March 14th, 2006, 10:08 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

There are bunch of API calls into the comdlg32 library floating around out there, but this is the leanest (fewest lines of code) I've ever come across. Clicking cmdGetFilePath opens the dialog and the selected path and file name are written to txtFilePath.

Private Type GetFilePath
  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 GetFileName Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (pOpenfilename As GetFilePath) As Long

Private Sub cmdGetFilePath_Click()

    Dim filePath As GetFilePath
    filePath.lStructSize = Len(filePath)
    filePath.hwndOwner = Me.Hwnd
    filePath.lpstrFilter = "All File Types" + Chr$(0) + "*.*"
    filePath.lpstrFile = Space$(254)
    filePath.nMaxFile = 255
    filePath.lpstrFileTitle = Space$(254)
    filePath.nMaxFileTitle = 255
    filePath.lpstrInitialDir = "D:\My Data"
    filePath.lpstrTitle = "File Copy"
    filePath.flags = 0

    Dim strFilePath

    strFilePath = GetFileName(filePath)

    If (strFilePath) Then
        Me.txtFilePath.Value = Trim$(filePath.lpstrFile)
    Else
        Exit Sub
    End If

End Sub

Bob

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to open a dialogue box maximized Pete Bone Visual C++ 0 October 10th, 2007 06:23 AM
open file dialog box mh VB.NET 7 April 11th, 2005 10:15 AM
Open Print dialogue box vladimir Access VBA 7 September 21st, 2004 08:46 AM
Open File Dialog Box KennethMungwira VB.NET 3 August 3rd, 2003 09:44 PM
Open File Dialog Box KennethMungwira VB.NET 2 June 27th, 2003 04:36 PM



All times are GMT -4. The time now is 12:46 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.