(2003 to 2005)

Send faxes from VB6 on a Win2k machine with a modem installed

Thu Dec 4 23:31:00 UTC+1100 2003


Sending faxes from VB6 (or any language that can consume COM) is easy with Win2k. The limitation with this particular method seems to be that the software has to be running on the same machine connected to the modem.

When you install a modem in Win2k a fax printer is automatically setup for you. You can print to this from any application that supports windows printing (like notepad). So if you created a new file in notepad, entered some random text, then printed it to the fax printer you would be prompted to enter the fax numbers of the recipents, etc. Then you could press send and your fax would go out.

To do this via code, so that you can programatically specify the fax number, etc. you can use one of two methods. One is to use a native C API, and the other is to use a COM component, both available in Win2k. There is heaps of info available about this feature in the MDSN Platform SDK doco.

In VB6 you can add a reference to the faxcom.dll and then use code like this:

  On Error GoTo goterr
  Screen.MousePointer = vbHourglass
  Dim oFaxServer As FAXCOMLib.FaxServer  
  Set oFaxServer = New FAXCOMLib.FaxServer
  Call oFaxServer.Connect(Me.Text1.Text)
  Dim oFaxDoc As FAXCOMLib.FaxDoc
  Set oFaxDoc = oFaxServer.CreateDocument(Me.Text2.Text)
  oFaxDoc.FaxNumber = Me.Text3.Text
  Call oFaxDoc.Send
  Call oFaxServer.Disconnect
  Call MsgBox("File has been sent to the fax queue.", vbOKOnly, "Success")
  Set oFaxDoc = Nothing
  Set oFaxServer = Nothing
  Screen.MousePointer = vbNormal
  Exit Sub
  Call MsgBox(Err.Description, vbOKOnly, "Error")
  GoTo endsub

Where Text1 contains the name of the local machine you are connecting to. Text2 contains the file location of a file fax and Text3 contains the fax number of a single recipient.

Note: files sent via this method must have correctly registered file extensions. I have only tested this with .txt and .xls files, but both worked fine. When printing the Excel file I noticed that Excel actually popped up on the screen for a short moment while the fax was being sent..


Copyright © 2003-2005 John Elliot