=========Reading from a file========== Dim dbs As Database Dim rst As Recordset Dim strRecordSource As String 'Source for recordset, can be SQL, table, or saved query Dim intFileDesc As Integer 'File descriptor for output file Dim strSourceFile As String 'Full path of source file Dim strTextLine As String 'Input buffer Dim strField1 As String 'Extracted Field1 from buffer Dim strField2 As String 'Extracted Field2 from buffer Dim strField3 As String 'Extracted Field3 from buffer Set dbs = CurrentDb Set rst = dbs.OpenRecordset(strRecordSource, dbOpenDynaset) intFileDesc = FreeFile Open strSourceFile For Input As #intFileDesc Do While Not EOF(intFileDesc) ' Loop until end of file. Line Input #intFileDesc, strTextLine 'Read line into buffer ' < use string handling to extract the fields from strTextLine ' and place them in strField1, strField2, & strField3 > rst.AddNew 'depending on your situation, you may want to find an ' existing record and Edit instead rst!Field1 = strField1 rst!Field2 = strField2 rst!Field3 = strField3 rst.Update Loop Close #intFileDesc 'Close input file rst.Close 'Close the recordset Set rst = Nothing 'Garbage handling before we exit the function Set dbs = Nothing ================================================================================================== =========Writing to a file========== Dim dbs As Database Dim rst As Recordset Dim intFileDesc As Integer 'File descriptor for output file (number used by OS) Dim strOutput As String 'Output string for entry Dim strRecordSource As String 'Source for recordset, can be SQL, table, or saved query Dim strOutfile As String 'Full path to output file Kill strOutfile 'Delete the output file before using it. 'Not necessary, but ensures you have a clean copy every time intFileDesc = FreeFile 'Get a free file descriptor Open strOutfile For Binary As #intFileDesc 'Open the output file for writing Set dbs = CurrentDb Set rst = dbs.OpenRecordset(strRecordSource) 'Open the recordset based on our source string While Not rst.EOF 'Loop until end of recordset strOutput = rst!Field1 & ";" & rst!Field2 & ";" & rst!Field3 Print #intFileDesc, strOutput 'Print output string to file rst.MoveNext 'Advance to next record in recordset Wend Close #intFileDesc 'Close output file rst.Close 'Close this recordset Set rst = Nothing 'Garbage handling before we exit the function Set dbs = Nothing ================================================================================================== =========Send output to the printer========== ' The trick is to use the string "LPT1:" for the output filename. The VBA recognises this ' is a reserved name for the parallel port. The following function (adapted from code written by ' Bill Mitchell, mitchell@wvmitchell.com) is a good example of how you might use it. It opens ' an external file, reads a line from it, and then sends the line to the printer. To write ' directly from a recordset, look at the "Writing to a file" code above, and modify it ' appropriately. ' ' Note sending the ascii character 12 at the end. This is important and shouldn't be left off. ' Character 12 is the formfeed character. Your printer won't eject the paper until it receives ' this character. Function PrintThis(strFilename) Dim strLine As String 'Line of text from the input file Dim intInputFile as Integer 'File descriptor for the input file Dim intOutputFile as Integer 'File descriptor for the output file intInputFile = FreeFile 'Get a new file descriptor for the input file intOutputFile = FreeFile 'Get a new file descriptor for the output file Open strFilename For Input As #intInputFile 'Open the input file Open "LPT1:" For Output As #intOutputFile 'Open the parallel port as a file Do While Not EOF(intInputFile) 'Loop until end of input file Line Input #intInputFile, strLine 'Read a line into the input buffer Print #intOutputFile, strLine 'Send the buffer to the printer Loop Print #intOutputFile, Chr(12) 'Send a formfeed character to the printer to eject the page Close #intInputFile, #intOutputFile 'Close the file descriptors End Function