[AccessD] Using FreeFile

Stuart McLachlan stuart at lexacorp.com.pg
Mon Oct 17 17:14:00 CDT 2022


Not a "filename", you get an internal "file handle". Which should be valid throughout your 
application until such time as the file is closed.

You can actually use that handle in another function. Consider this:

Function Doit() As Long
Dim ff As Long
ff = FreeFile
If Dir$("test.txt") > "" Then Kill "test.txt"
Open "test.txt" For Append As #ff
Print #ff, "First Line"
Doit2 (ff)
Print #ff, "Third Line"
Close #ff
Checkit
End Function

Function Doit2(ff As Long) As Long
Print #ff, "Second Line"
End Function

Function Checkit() As Long
Dim ff As Long
Dim s As String
ff = FreeFile
Open "test.txt" For Input As #ff
While Not EOF(ff)
Line Input #ff, s: Debug.Print s
Wend
Close ff
Kill "test.txt"
End Function




On 17 Oct 2022 at 15:36, Arthur Fuller wrote:

> I'm still trying to get my head around using FreeFile. The basics are
> simple enough: 1. call freefile, get an available filename 2. open
> said file 3. write stuff to it 4. close said file
> 
> In the demo I'm looking at (from MS Learn), it's all self-contained in
> one sub. A couple of things puzzle me. First is step 3, Write. Having
> performed steps 1 and 2, if I now move into another function, is the
> opened file still available to write to? If I call another function,
> and then return to the original file (which created and opened the
> freefile), and then close the file, will that work?
> 
> -- 
> Arthur
> -- 
> AccessD mailing list
> AccessD at databaseadvisors.com
> https://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
> 




More information about the AccessD mailing list