Advertisement

06.28.2004 at 06:58PM PDT, ID: 21041263
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Opening and reading a text file - VBA
Tags: vba, file, text, read
I know I have seen other posts on here, but I'm looking from as simple as possible:

I'm trying to go thorugh a text file line by line, parse the line into seperate variables, then insert them into a table.

I would to have the user be able to browse to the file they want parsed, then from a command button... import the txt file.

If anyone can give me a quick and easy solution, i'd really appreciate it.

Tigger
Start your free trial to view this solution
Question Stats
Zone: Microsoft
Question Asked By: Tigger996
Solution Provided By: rockmuncher
Participating Experts: 3
Solution Grade: A
Views: 864
Translate:
Loading Advertisement...
06.28.2004 at 07:34PM PDT, ID: 11422304

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.28.2004 at 08:11PM PDT, ID: 11422493

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.28.2004 at 09:41PM PDT, ID: 11422817

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.28.2004 at 10:24PM PDT, ID: 11422942

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.29.2004 at 10:33AM PDT, ID: 11428391

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.13.2004 at 01:56AM PDT, ID: 12042188

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
06.28.2004 at 07:34PM PDT, ID: 11422304

Rank: Master

In ACC97 you would use the Common Dialog Controls library (which you need to reference using Tools - References from a code window).  

Here's an example from the Microsoft MSDN site:

Private Sub mnuFileOpen_Click ()
Dim strFileToOpen as variant

   ' CancelError is True.
   On Error GoTo ErrHandler
   ' Set filters.
   CommonDialog1.Filter = "All Files (*.*)|*.*|Text _
   Files (*.txt)|*.txt|Batch Files (*.bat)|*.bat"
   ' Specify default filter.
   CommonDialog1.FilterIndex = 2

   ' Display the Open dialog box.  User makes selection
   CommonDialog1.ShowOpen

   strFileToOpen=CommonDialog1.FileName & ""

    '<PUT CODE TO OPEN AND IMPORT HERE>'

   Exit Sub

ErrHandler:
' User pressed Cancel button.
   Exit Sub
End Sub


The user selection is stored in the FileName property of the CommonDialog1 control on a form. To reference it you simply use strFileToOpen=CommonDialog1.FileName & ""


For more info see the article on MSDN at http://msdn.microsoft.com/library/en-us/vbcon98/html/vbcondisplayingopensaveasdialogboxes.asp?frame=true

Accepted Solution
 
06.28.2004 at 08:11PM PDT, ID: 11422493

Rank: Master

In later versions of Access you can use the FileDialog property of the Application object.

Here is an extract from the MSAccess help file:

Using the FileDialog object
Use the FileDialog property to return a FileDialog object. The FileDialog property is located in each individual Office application's Application object. The property takes a single argument, DialogType, that determines the type of FileDialog object that the property returns. There are four types of FileDialog object:

Open dialog box - lets users select one or more files that you can then open in the host application using the Execute method.
SaveAs dialog box - lets users select a single file that you can then save the current file as using the Execute method.
File Picker dialog box - lets users select one or more files. The file paths that the user selects are captured in the FileDialogSelectedItems collection.
Folder Picker dialog box - lets users select a path. The path that the user selects is captured in the FileDialogSelectedItems collection.
Each host application can only instantiate a single instance of the FileDialog object. Therefore, many of the properties of the FileDialog object persist even when you create multiple FileDialog objects. Therefore, make sure that you've set all of the properties appropriately for your purpose before you display the dialog box.

In order to display a file dialog box using the FileDialog object, you must use the Show method. Once a dialog box is displayed, no code will execute until the user dismisses the dialog box. The following example creates and displays a File Picker dialog box and then displays each selected file in a message box.

Sub Main()

    Dim fd As FileDialog                                                    'Declare a variable as a FileDialog object
    Set fd = Application.FileDialog(msoFileDialogFilePicker)  'Create a FileDialog object as a File Picker dialog box.

    'Declare a variable to contain the path of each selected item. Even though the path is a String,
    'the variable must be a Variant because For Each...Next routines only work with Variants and Objects.
    Dim vrtSelectedItem As Variant

   
    With fd                                                                       'Use a With...End With block to reference the FileDialog object to loop thru multiple files.

        'Use the Show method to display the File Picker dialog box and return the user's action.
        'The user pressed the action button.
        If .Show = -1 Then

            'Step through each string in the FileDialogSelectedItems collection.
            For Each vrtSelectedItem In .SelectedItems

                'vrtSelectedItem is a String that contains the path of each selected item.
                'You can use any file I/O functions that you want to work with this path.
                'This example simply displays the path in a message box.
                MsgBox "The path is: " & vrtSelectedItem

            Next vrtSelectedItem
        'The user pressed Cancel.
        Else
        End If
    End With

    'Set the object variable to Nothing.
    Set fd = Nothing

End Sub
 
06.28.2004 at 09:41PM PDT, ID: 11422817
For some reason I cannot access FileDialog.  Do I have to add a reference?  And what reference?

Tigger
 
06.28.2004 at 10:24PM PDT, ID: 11422942

Rank: Guru

am i wrong, or hasn't the subject of the actual *file parsing* been addressed yet at all?  as for the file open dialog, check out this link:

http://www.mvps.org/access/api/api0001.htm

but as for the file parsing, for a start i can post code that i wrote to parse a file that consists of "keyword value" pairs, e.g.,

projectname testproject
numberofnodes 15
network dual

etc....

the function i wrote accepts the filename (including path) as input and fills the found values and keys into a table (which is flushed first); the number of read lines is returned.  even though this probably isn't exactly what you need, maybe it helps to give you an idea.  if you get more specific about your requirements, i can help you make the code more customized.  ok, here we go (this is DAO code, so make sure that under Tools > References "Microsoft DAO ... Object Library" is checked and above "Microsoft ActiveX Data Objects ... Library"):

Public Function readWizardFile(ByVal filename As String) As Integer
 
  Dim fhandle As Integer
  Dim fline As String
  Dim first_space As Integer
  Dim line_k As String
  Dim line_v As String
  Dim db As Database
  Dim sql As String
 
  Set db = CurrentDb
 
  ' flush tblTempWizSpec
  db.Execute ("DELETE * FROM [tblTempWizSpec]")
 
  fhandle = FreeFile()
  Open filename For Input Access Read Lock Write As #fhandle
 
  ' reset counter
  readWizardFile = 0
 
  While (Not (EOF(fhandle)))
    Line Input #fhandle, fline
   
    ' count lines
    readWizardFile = readWizardFile + 1
   
    fline = Trim(fline)  ' cut off spaces
    ' look for first space
    first_space = InStr(fline, " ")
    ' if no space found, value will be empty
    If (first_space = 0) Then
      line_k = fline
      line_v = ""
    Else
      ' build keyword and value
      line_k = Left$(fline, (first_space - 1))
      line_v = Right$(fline, (Len(fline) - first_space))
    End If
   
    ' replace double quotes with single quotes
    While (InStr(line_k, Chr(34)) > 0)
      Mid$(line_k, InStr(line_k, Chr(34)), 1) = "'"
    Wend
    While (InStr(line_v, Chr(34)) > 0)
      Mid$(line_v, InStr(line_v, Chr(34)), 1) = "'"
    Wend
   
    sql = "INSERT INTO [tblTempWizSpec] ([Keyword], [Value]) VALUES (" & Chr(34) & line_k & Chr(34) & ", " & Chr(34) & line_v & Chr(34) & ")"
    db.Execute sql
  Wend
 
  Close #fhandle
     
End Function


--bluelizard
Assisted Solution
 
06.29.2004 at 10:33AM PDT, ID: 11428391
I got it all working.  Thanks for all your help.

Tigger
 
09.13.2004 at 01:56AM PDT, ID: 12042188
Hi,

I have developed a database for a number of users to input information by means of a form. I need to put a control on the form which will give an indication of the username of the user who input the data or change a record.  Can anyone assist?
 
 
20080236-EE-VQP-29