
Module works, except when form passes arguements
I don't have any problem with a code similar to yours. My test code is:
****
Public Function TextFileRead()
'Dim lngFileNo As Long
Dim strFileName As String, strLine As String
lngFileNo = FreeFile()
strFileName = "C:\My Documents\desktop.ini"
'Open strFileName For Input As #lngFileNo
Open strFileName For Input As #1
'Line Input #lngFileNo, strLine
Line Input #1, strLine
Debug.Print strLine
Close
End Function
****
Note that you should declare the Sub
Sub ImportLFDelimitedFile2( _
txtInputFile As Variant, _
txtInputtblArt, _
txtInputtblAut As Variant)
You should also use FreeFile rather than an explicit constant for FileNo.
Check Access Help on FreeFile function.
If txtImportFile, txtImpArticle, txtImpAuthor are TextBoxes on your Form,
perhaps (guessing here) you should call them using more explicit references
such as:
Call ImportLFDelimitedFile2(Me.txtImportFile.Value, _
Me.txtImpArticle.Value, Me.txtImpAuthor.Value)
HTH
Van T. Dinh
Quote:
> The code from the form and module are below. I enter data into form text
> boxes and then click a command button which passes the information to a
> module. The code is supposed to open and read a text file for importing
> into tables.
> I have message boxes in the code to test and see that information is
> correctly passed (see below). The first text box tells me the values
passed
> from the form and these values are correct and have quotes around them as
> they should (strings). But the second msgbox doesn't have any data from
the
> text file, so it doesn't look like the text file is being opened
correctly.
> The odd part is if I call the sub from the immediate window the code works
> fine. Parenthetcially, If I manually enter the values into variables, the
> code works fine too.
> What am I missing????
> TIA
> CODE:
> In Form (On Click)
> Call ImportLFDelimitedFile2(txtImportFile, txtImpArticle, txtImpAuthor)
> In Module
> Sub ImportLFDelimitedFile2(txtInputFile, txtInputtblArt, txtInputtblAut As
> Variant)
> On Error Resume Next
> Dim szInput As Variant, db As Database, rs As Recordset
> Dim ID As Integer
> Dim Count, CountTotal As Integer
> Set db = CurrentDb()
> MsgBox "Here are the values " & txtInputFile & " " & txtInputtblArt &
"
> " & txtInputtblAut, vbOKOnly, "Everything is okay"
> Open txtInputFile For Input As 1
> Do
> Set rs = db.OpenRecordset(txtInputtblArt)
> Line Input #1, szInput
> MsgBox " Here is " & szInput, vbOKOnly