Module works, except when form passes arguements 
Author Message
 Module works, except when form passes arguements

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



Thu, 29 Jan 2004 21:35:07 GMT  
 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



Fri, 30 Jan 2004 10:37:21 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Passing a report object as an arguement to a form using prtdevmode and name

2. Pass HTML form to a function as an arguement

3. Passing input box value from Form Module to report module

4. Pass variable form module to a form

5. How do you pass from obj from one form to a module/forms

6. passing forms and controls so I can set focus back to a form from a module

7. passing forms and controls so I can set focus back to a form from a module

8. How to get a control as a function arguement in the COM(Exe) module

9. Close forms by VBA-prcedure except active and start form

10. Problem with passing an ArrayList as an arguement

11. Newbie wants to pass arrays as arguement

12. VB5 passing arguements, user defined types and arrays

 

 
Powered by phpBB® Forum Software