Rabu, 02 November 2016

[MS_AccessPros] reading a text file


Under the gun so I could use some help.


I’m trying to read a text file and it is saying file not found.


I have a browse button that returns this to a text file:


Function LaunchCD(strform As Form) As String

    Dim OpenFile As OPENFILENAME

    Dim lReturn As Long

    Dim sFilter As String

    OpenFile.lStructSize = Len(OpenFile)

    OpenFile.hwndOwner = strform.Hwnd

    sFilter = "Txt: (*.txt)"

    OpenFile.lpstrFilter = sFilter

    OpenFile.nFilterIndex = 1

    OpenFile.lpstrFile = String(257, 0)

    OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1

    OpenFile.lpstrFileTitle = OpenFile.lpstrFile

    OpenFile.nMaxFileTitle = OpenFile.nMaxFile

    OpenFile.lpstrInitialDir = "C:\"

    OpenFile.lpstrTitle = "Select a file using the Common Dialog DLL"

    OpenFile.flags = 0

    lReturn = GetOpenFileName(OpenFile)

        If lReturn = 0 Then

            MsgBox "A file was not selected!", vbInformation, _

              "Select a file using the Common Dialog DLL"


            LaunchCD = Trim(Left(OpenFile.lpstrFile, InStr(1, OpenFile.lpstrFile, vbNullChar) - 1))

         End If

End Function


.And then gets passed to this after a submit button:



Sub ReadTheFile(strFname As String)

   On Error GoTo err_out

   Dim linetxt As String

   Dim fso, MyFile

   Set fso = CreateObject("Scripting.FileSystemObject")

   Set MyFile = fso.OpenTextFile("strFname", 1)

   linetxt = MyFile.ReadLine

   MsgBox (linetxt)



   GoTo exit_out


   MsgBox ("Error in ReadTheFile: " & Err.Number & vbCrLf & Err.Description)



End Sub


Any ideas?

p.s.  the code is scrappy because I’m testing as I go.




Liz Ravenwood

Programmer / Analyst

B/E Aerospace | Super First Class Environments


1851 S Pantano Road | Tucson, Arizona 85710

Office +1.520.239.4808 | Internal 814-4808


Passion to Innovate. Power to Deliver


This email (and all attachments) is for the sole use of the intended recipient(s) and may contain privileged and/or proprietary information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message.


Posted by: Liz Ravenwood <Liz_Ravenwood@beaerospace.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (1)

Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.



Tidak ada komentar:

Posting Komentar