Copyright 07.1995 CONNECT Software, All rights reserved.

	created    : Jul-27-95 - last update : Aug-01-95
	version    : 1.1
	written by : Pascal Duquesne

-----------------------------------------------------------------

Title : 1.1 Change default printer / port
Keys : ACCESS PRINTER PORT DEFAULT PRINT SETUP GETPROFILESTRING LPT

If you have any comments about this code, please e-mail them to
Pascal Duquesne at 75474,3312.


This code is designed to change the default printer from within 
Access Basic without having to go to control panel and above all 
without user intervention (it means you have to know the printer
name you want to make active).


You can find your printer names below [Devices] in WIN.INI but 
make sure the printer name your specify with SetPrinterPort() 
complies with the following syntax : 
      "PRINTER NAME,DRIVER NAME,PORT NAME"
ex :  "HP LaserJet III,hppcl5a,LPT3:"


I wrote this code because Access Basic does not provide any
function to switch from LPT1 to LPT3.


To use it, simply paste the code below into a new Module.  Then
call it from anywhere in your code. 

I did not include any error-handling routine.


-----------------------------------------------------------------

Revisions :
---------
1.1  - adds a few comments
     - removes the function IsValid() I forgot to provide with the
       first version and uses instead IsNull()
     



-----------------------------------------------------------------

Examples :
--------
   'my LPT1 = Okidata ML 320,OKI9,LPT1:
   'my LPT3 = HP LaserJet III,hppcl5a,LPT3:

Considering your default printer is configured on LPT1 and you want
to print to LPT3.  Your Access Basic code should be :

   ' *** save default prt
   oldPrinterPort = GetPrinterPort() 
   ' *** chg default prt
   SetPrinterPort("HP LaserJet III,hppcl5a,LPT3:")  
   ...
   ...
   ...
   ' *** restore default prt
   SetPrinterPort(oldPrinterPort)                   



*****************************************************************
ACCESS BASIC CODE
*****************************************************************

Declare Function GetProfileString Lib "Kernel" (ByVal SName$, ByVal KName$, ByVal Def$, ByVal Ret$, ByVal Size%) As Integer
Declare Function WriteProfileString Lib "Kernel" (ByVal SName$, ByVal KName$, ByVal Def$) As Integer


Function GetPrinterPort () As String

    Dim ReadString As String * 255, returnv As String
    Dim mResultLen As Integer        

    mResultLen = GetProfileString("Windows", "Device", "(Unassigned)", ReadString, Len(ReadString) - 1)    

    If IsNull(ReadString) Then
        returnv = ""
    Else
        returnv = Left(ReadString, InStr(ReadString, Chr$(0)) - 1)
    End If
    GetPrinterPort = returnv

End Function



Function SetPrinterPort (ByVal mport As String) As Integer

    SetPrinterPort = WriteProfileString("Windows", "Device", mport) <> 0

End Function

