Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access to Winfax Code Problem

Status
Not open for further replies.

cranebill

IS-IT--Management
Jan 4, 2002
1,113
US
Ok here is something i got From the rptsmp00 (from Microsoft, tested and run on windows 95 and Winfax 7)and i am running windows XP Pro and Winfax 10.02. After modifying a couple things, for 1 it would not recognize that winfax was actually open, so i have some code to open winfax, and then DDE would need a specific date format which i changed. Now i am getting anoother error which im not sure what to do. Here is the complete Code:

Option Compare Database
Option Explicit

Global strInvoiceWhere

Declare Function FindWindow& Lib "user32" Alias "FindWindowA" (ByVal IpClassName As String, ByVal IpWindowName As String) ' WinFax only
Function WinFaxInvoices()


Dim dbsNorthwind As Database
Dim rstCustomers As Recordset
Dim intSendFaxReturnVal As Integer


Set dbsNorthwind = CurrentDb()
Set rstCustomers = dbsNorthwind.OpenRecordset("Customers", dbOpenDynaset)

intSendFaxReturnVal = -1
If MsgBox("Do you want to fax invoices" & Chr(13) & "to all customers using WinFax?", 4) = 6 Then
intSendFaxReturnVal = -1
With rstCustomers
Do Until .EOF Or intSendFaxReturnVal = 0
strInvoiceWhere = "[customerid] = '" & ![CustomerID] & "'"
intSendFaxReturnVal = SendWinFax(![ContactName], ![Fax], "rptWinFaxInvoice")
.MoveNext
Loop
End With
End If

End Function

Function SendWinFax(strFaxName As String, strFaxNumber As String, strReportName As String) As Integer


Dim lngChannelNumber As Long
Dim strFaxStatus As String
Dim FaxTime As String
Dim strRecipFaxNum As String
Dim strRecipTime As String
Dim strRecipDate As String
Dim strRecipName As String
Dim strRecipient As String

On Error GoTo SendWinFax_Error



Dim objWFXSend As New wfxctl32.CSDKSend


strRecipFaxNum = Chr$(34) & strFaxNumber & Chr$(34)
strRecipTime = Chr$(34) & Format$(Now, "h:nn:ss") & Chr$(34)
strRecipDate = Chr$(34) & Format$(Date, "mm/dd/yy") & Chr$(34)
strRecipName = Chr$(34) & left$(strFaxName, 24) & Chr$(34)

strRecipient = strRecipFaxNum & "," & strRecipTime & "," & strRecipDate & "," & strRecipName


lngChannelNumber = DDEInitiate("faxmng32", "CONTROL")
strFaxStatus = DDERequest(lngChannelNumber, "STATUS")

While strFaxStatus Like "Busy*"
strFaxStatus = DDERequest(lngChannelNumber, "STATUS")
Wend

lngChannelNumber = DDEInitiate("FAXMNG", "TRANSMIT")

DDEPoke lngChannelNumber, "Sendfax", "recipient(" & strRecipient & ")"
DDEPoke lngChannelNumber, "Sendfax", "showsendscreen(""0"")"

DoCmd.OpenReport strReportName, A_NORMAL

SendWinFax = -1





SendFax_Exit:

DDETerminateAll
lngChannelNumber = False
Exit Function



SendWinFax_Error:
MsgBox "Error:" + Error$, 0, "SendFaxl"
Resume SendFax_Exit


End Function


The error i get is Invalid Use of Null located in this line:
intSendFaxReturnVal = SendWinFax(![ContactName], ![Fax], "rptWinFaxInvoice")

Any Ideas?

Thanx Bill
 
Here is the original code before i modified it if this helps.

Option Compare Database
Option Explicit

Global strInvoiceWhere ' Global for both MSFax and WinFax examples

Declare Function FindWindow& Lib "user32" Alias "FindWindowA" (ByVal IpClassName As String, ByVal IpWindowName As String) ' WinFax only








'********************************************************************************************
' This function will walk through the Customers table and fax the Invoices report which
' is filtered by the CustomerId field using MSFax through Access SendObject.
'
' This function assumes the report rptMSFaxInvoices has the default printer set to MSFax
' and the MSFax driver is installed correctly.
' *******************************************************************************************
'
Function MSFaxInvoices()

'********************************************************************************************
' Diming all variables
'********************************************************************************************

Dim dbsNorthwind As Database
Dim rstCustomers As Recordset

'********************************************************************************************
' Setting database and recordset variables
'********************************************************************************************

Set dbsNorthwind = CurrentDb()
Set rstCustomers = dbsNorthwind.OpenRecordset("Customers", dbOpenDynaset) ' Set Recordset to Customers table

'********************************************************************************************
' Walking through the Customers recordset until end of file, setting the global variable
' strInvoicesWhere to the current where and using SendObject passing
' customers fax number and report name.
'********************************************************************************************

If MsgBox("Do you want to fax invoices" & Chr(13) & "to all customers using MSFax?", 4) = 6 Then
With rstCustomers
Do Until .EOF
strInvoiceWhere = "[customerid] = '" & ![CustomerID] & "'" ' sets global strInvoiceWhere
DoCmd.SendObject acReport, "rptMSFaxInvoice", acFormatRTF, "[fax: " & ![Fax] & "]", , , , , False ' Runs Report to MSFax
.MoveNext ' Move to next record in Recordset
Loop
End With
End If


End Function





'********************************************************************************************
' This function will walk through the Customers table and fax the Invoices report which
' is filtered by the CustomerId field using the user defined function SendWinFax. SendWinFax
' is located in this module.
'
' This function assumes the report rptWinFaxInvoices default printer is set to Delrina
' MAPI Services and WinFax Pro is correctly installed.
' *******************************************************************************************
Function WinFaxInvoices()

'********************************************************************************************
' Diming all varibles
'********************************************************************************************

Dim dbsNorthwind As Database
Dim rstCustomers As Recordset
Dim intSendFaxReturnVal As Integer

'********************************************************************************************
' Setting database and recordset varibles
'********************************************************************************************

Set dbsNorthwind = CurrentDb()
Set rstCustomers = dbsNorthwind.OpenRecordset("Customers", dbOpenDynaset) ' Set Recordset to Customers table

'********************************************************************************************
' Walking throgugh the Customers recordset until end of file, setting the golbal varible
' strInvoicesWhere to the current where and calling SendWinFax passing the Customers Name,
' Customers Fax number and Report name.
'********************************************************************************************

intSendFaxReturnVal = -1 ' Priming return value to True
If MsgBox("Do you want to fax invoices" & Chr(13) & "to all customers using WinFax?", 4) = 6 Then ' Make sure user wants to send fax to customers
intSendFaxReturnVal = -1 ' Priming return value to True
With rstCustomers
Do Until .EOF Or intSendFaxReturnVal = 0 ' start do until end of file or return value = false
strInvoiceWhere = "[customerid] = '" & ![CustomerID] & "'" ' sets global strInvoiceWhere
intSendFaxReturnVal = SendWinFax(![ContactName], ![Fax], "rptWinFaxInvoice") 'Call user defined function and pass in data
.MoveNext ' Move to next record in Recordset
Loop
End With
End If

End Function

'
'
'********************************************************************************************
' Create Date 4/15/96
'
' SendWinFax function will fax any report to any phone number, and address it to any name
' which was provided in the variables.
'
' This function was *ONLY* tested under Win95 and WinFax 7.0 with the patch installed
' from Delrina. The patch "wf702d1.exe" can be found on ' Without the patch you may get IPF's when running this code.
'
'************Microsoft Product Support only supports Microsoft Products.*********************
'
'********************************************************************************************
'
'
'
Function SendWinFax(strFaxName As String, strFaxNumber As String, strReportName As String) As Integer

'********************************************************************************************
' Diming all variables
'********************************************************************************************

Dim lngChannelNumber As Long
Dim strFaxStatus As String
Dim FaxTime As String
Dim strRecipFaxNum As String
Dim strRecipTime As String
Dim strRecipDate As String
Dim strRecipName As String
Dim strRecipient As String

On Error GoTo SendWinFax_Error 'Error Trap

'********************************************************************************************
' If WinFax is closed then none of the fax functionality will be run.
' Be aware that there may be timing issues when trying to start WinFax in this function.
' I elected to have the user start WinFax manually for this example.
'********************************************************************************************

If FindWindow("Sfaxmng", "Delrina Winfax PRO") > 0 Then

'********************************************************************************************
' Building Recipient string to send in DDEPoke
'********************************************************************************************

strRecipFaxNum = Chr$(34) & strFaxNumber & Chr$(34)
strRecipTime = Chr$(34) & Format$(Now, "h:nn:ss") & Chr$(34)
strRecipDate = Chr$(34) & Date & Chr$(34)
strRecipName = Chr$(34) & left$(strFaxName, 24) & Chr$(34)

strRecipient = strRecipFaxNum & "," & strRecipTime & "," & strRecipDate & "," & strRecipName

'********************************************************************************************
' Start of DDE section
'********************************************************************************************

lngChannelNumber = DDEInitiate("faxmng32", "CONTROL") 'Initiate DDE connection
strFaxStatus = DDERequest(lngChannelNumber, "STATUS") 'Get and set status of DDE connection

'If busy then loop until not busy
While strFaxStatus Like "Busy*"
strFaxStatus = DDERequest(lngChannelNumber, "STATUS")
Wend

lngChannelNumber = DDEInitiate("FAXMNG", "TRANSMIT") 'set ChannelNumber to current DDE Channel

DDEPoke lngChannelNumber, "Sendfax", "recipient(" & strRecipient & ")" 'Poke recipient data
DDEPoke lngChannelNumber, "Sendfax", "showsendscreen(""0"")" 'Poke to showscreen

'DDEPoke lngChannelNumber, "Sendfax", "setcoverpage(""Cover Page"" )" 'Untested Other Poke examples
'DDEPoke lngChannelNumber, "Sendfax ", "fillcoverpage(""Stuff to go inside."")" 'Untested Other Poke examples
'DDEPoke lngChannelNumber, "SendFax", "resolution(""HIGH"")" 'Untested Other Poke examples

'********************************************************************************************
' Run the Report
'********************************************************************************************
DoCmd.OpenReport strReportName, A_NORMAL

SendWinFax = -1 ' setting return value to True

Else 'If WinFax is not started
MsgBox "Please Start WinFax and try again" 'Prompt
SendWinFax = 0 ' setting return value to False
End If

'********************************************************************************************
' Exit Stuff
'********************************************************************************************

SendFax_Exit:

DDETerminateAll 'Terminate all links.
lngChannelNumber = False 'Set lngChannelNumber to false clears the varible.
Exit Function 'All Done

'********************************************************************************************
' Error Trap
'********************************************************************************************

SendWinFax_Error:
MsgBox "Error:" + Error$, 0, "SendFaxl" 'Print Error message and number
Resume SendFax_Exit


End Function




Bill
 
You cannot assign a Null value to a string, so if any of your passed data in ![ContactName] or ![Fax] = null, the parameters strFaxName As String, strFaxNumber As String will generate an error. There are a number of ways to handle this, but good practice is to explicity handle the nulls before passing them to the function. For example, I may want to send the fax anyway if I don't have the Contact name, but I know the fax won't go if the fax number is null, so I might code it like this:

dim sContact as String

if not isnull(!Contact)

sContact=!Contact
else
sContact="To Whom It May Concern"
endif




if not isnull(![Fax] )


intSendFaxReturnVal = SendWinFax(sContact, ! [Fax], "rptWinFaxInvoice")

end if

.movenext






 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top