Wrox Programmer Forums
|
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 10th, 2006, 09:25 AM
Authorized User
 
Join Date: Oct 2005
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default Open .dat and saveas .txt

Ok, here is my problem. We have a barcode scanner that saves all logs as a .dat format. I need to import those records and print from the results. I tried to do a manual import the first time to get a schema file but access does allow me to select a .dat file. So I was wondering if I could select a dat file and save it as a txt file in access/vba.

 
Old March 10th, 2006, 09:53 AM
Authorized User
 
Join Date: Mar 2006
Posts: 80
Thanks: 0
Thanked 0 Times in 0 Posts
Default

There is no way to easy import *.dat files into Access. You must know internal structure of this file (ask dealer, or developer of this scanner, how it work with this file). Probably you must open this file in binary (maybe text) mode and then you read what you want and save it to DB).

Peko

 
Old March 10th, 2006, 10:09 AM
Authorized User
 
Join Date: Oct 2005
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default

So there is no way of using vba to change a file extension from .dat to .txt??

 
Old March 10th, 2006, 11:35 AM
Authorized User
 
Join Date: Mar 2006
Posts: 80
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No, it isn't

 
Old March 10th, 2006, 12:24 PM
Authorized User
 
Join Date: Jun 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is the .dat file just a text file? If so, you should be able to import the file. You'd have to know how the scanner formatted the data, though: is it comma-delimited, tab-delimited, or maybe fixed-length?
 
Old March 10th, 2006, 09:21 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

 
Quote:
quote:So there is no way of using vba to change a file extension from .dat to .txt??


Sure there is:

Sub CopyFiles(strFilesToCopy As String, strDestinationDirectory As String)

    ' Call with CopyFiles "C:\Temp\*.dat", "C:\Temp"

    Dim strSourceFile As String
    Dim strDestinationFile As String
    Dim strSourceDirectory As String ' "C:\Temp\"

    strSourceDirectory = Left$(strFilesToCopy, (InStr(strFilesToCopy, "*") - 1))

    strSourceFile = Dir(strFilesToCopy)

    Do While strSourceFile <> ""

        strDestinationFile = Replace$(strSourceFile, ".DAT", ".TXT")
        FileCopy strSourceDirectory & strSourceFile, strDestinationDirectory & "\" & strDestinationFile

        strSourceFile = Dir

    Loop

End Sub

Not sure what the text file will look like in your case, but you may find, as hashtlishnii mentioned, that the .dat file is just a text file.

HTH,

Bob

 
Old March 10th, 2006, 09:51 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Also, if you'd like to just take a quick peak at a few lines of the file, you could use somethng like:

Sub ViewDatFileLines()
    Dim MyString As String
    Open "C:\Temp\Test.dat" For Input As #1
    Do While Not EOF(1)
        Line Input #1, MyString
        MsgBox MyString
    Loop
    Close #1
End Sub

That'll give you an idea of the format.

Bob






Similar Threads
Thread Thread Starter Forum Replies Last Post
SaveAs dialog box jbetts1967 Javascript How-To 1 September 20th, 2008 04:50 AM
DAT File Extension open in DotNet Framework bala2 General .NET 0 August 27th, 2007 08:30 AM
can't open txt file by clicking icon for it ALEX_GRIM Beginning VB 6 6 February 7th, 2005 03:52 PM
MODI.Document.SaveAs Method hannah_h VB.NET 2002/2003 Basics 5 January 13th, 2005 09:09 AM
How to open Binary .dat file? bekim VB.NET 2002/2003 Basics 2 June 16th, 2004 09:56 AM





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