Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 13th, 2006, 08:09 AM
Registered User
 
Join Date: Mar 2006
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
 
Old March 13th, 2006, 03:50 PM
Friend of Wrox
 
Join Date: Mar 2004
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
 
Old March 14th, 2006, 04:28 AM
Registered User
 
Join Date: Mar 2006
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.

 
Old March 14th, 2006, 11:06 AM
Authorized User
 
Join Date: Mar 2006
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

 
Old March 14th, 2006, 10:08 PM
Friend of Wrox
 
Join Date: Jun 2003
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






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





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