Mismatch compiler error

  • Thread starter Thread starter Bill
  • Start date Start date
B

Bill

The Sub statement for SendMailWithOE clearly shows
its 3rd argument as string. Yet, when I try to compile my
code: SendMailWithOE strSubj, strBody, strTO, ZipName
I get the message: "ByRef argument type mismatch" The
Dim statement for the arguments used also clearly show as
string... Dim strTO, ZipName, strSubj, strBody As String

Public Sub SendMailWithOE(ByVal vSubject As String, _
ByVal vMessage As String, _
ByRef vRecipients As String, _
Optional ByVal vFiles As String)

I don't know why the 3rd argument is being passed ByRef,
but I can't see why that would cause problems unless the
compiler is confused and isn't inserting the address of the
string.

Any ideas?
Thanks,
Bill
 
Bill said:
The Sub statement for SendMailWithOE clearly shows
its 3rd argument as string. Yet, when I try to compile my
code: SendMailWithOE strSubj, strBody, strTO, ZipName
I get the message: "ByRef argument type mismatch" The
Dim statement for the arguments used also clearly show as
string... Dim strTO, ZipName, strSubj, strBody As String

Public Sub SendMailWithOE(ByVal vSubject As String, _
ByVal vMessage As String, _
ByRef vRecipients As String, _
Optional ByVal vFiles As String)

I don't know why the 3rd argument is being passed ByRef,
but I can't see why that would cause problems unless the
compiler is confused and isn't inserting the address of the
string.

Any ideas?

Not unless you post your code that declares the arguments and calls the
function.
 
Dirk,
Below is all the code involved... more than you need, but
shouldn't, hopefully, leave any un-answered questions.

Bill

++++++++++++++(MY CODE)++++++++++++++++++++++++++++++++++++++++++
Option Compare Database
Option Explicit
Dim strTO, ZipName, strSubj, strBody As String 'To who; Zip file
name; e-mail subject; e-mail body text
Dim File1, File2, File3, File4, File5 As Variant 'The file name
and path
Dim F1Sel, F2Sel, F3Sel, F4Sel, F5Sel As String 'Is file selected for
inclusion?
---------------------------------------------------------------------------------------
Public Function SendADFData()
Dim WinZip As String
Dim FileList As String
Dim ShellString As Variant

'=========================================================================
' First we get our local copies of the distribution parameters.
'=========================================================================
LoadDistParms

'=========================================================================
' Next, we build the list of files to zip
'=========================================================================
FileList = ""
If F1Sel Then FileList = File1
If F2Sel And Len(File2 & "") > 0 Then FileList = FileList & " " & File2
If F3Sel And Len(File3 & "") > 0 Then FileList = FileList & " " & File3
If F4Sel And Len(File4 & "") > 0 Then FileList = FileList & " " & File4
If F5Sel And Len(File5 & "") > 0 Then FileList = FileList & " " & File5


'=========================================================================
' We use Terry Kreft's ShellWait to Shell to Winzip to zip the ADF data
' files down to a reasonable size suitable for an e-mail attachment.
'=========================================================================

WinZip = "c:\Program Files\Winzip\wzzip.exe"
ShellString = WinZip & " -P " & ZipName & " " & FileList

ShellWait (ShellString)

'=========================================================================
' Okay, with our zip file in hand, we now use Lyle Fairfield's code to
' attach our zip file to an Outlook Express hosted e-mail and send it to
' whoever is specified in the strTO.
'=========================================================================

SendMailWithOE strSubj, strBody, strTO, ZipName


End Function
----------------------------------------------------------------------------------------------------------
Public Sub LoadDistParms()
Dim con As ADODB.Connection
Dim rsDParms As ADODB.Recordset
Dim rsAtt As ADODB.Recordset
Dim stSQL As String

'==========================================================================
' This routine fetches the content of the "Distribution Parameters" table.
'==========================================================================

Set con = Application.CurrentProject.Connection

'Open the parameter table.
stSQL = "SELECT * FROM [DistParms]"
Set rsDParms = New ADODB.Recordset
rsDParms.Open stSQL, con, adOpenKeyset, adLockOptimistic

strTO = rsDParms!DistTO
ZipName = rsDParms!DistZIPName
strSubj = rsDParms!DistSubj
strBody = rsDParms!DistBody

F1Sel = rsDParms!DistFile1Sel
File1 = rsDParms!DistFile1

F2Sel = rsDParms!DistFile2Sel
File2 = rsDParms!DistFile2

F3Sel = rsDParms!DistFile3Sel
File3 = rsDParms!DistFile3

F4Sel = rsDParms!DistFile4Sel
File4 = rsDParms!DistFile4

F5Sel = rsDParms!DistFile5Sel
File5 = rsDParms!DistFile5

'Close the properties table recordset.
rsDParms.Close
Set rsDParms = Nothing

Set con = Nothing

End Sub



++++++++++++++(LYLE FAIRFIELD'S CODE)+++++++++++++++++++++++++++++++++++++
Option Compare Database
'======================================================================================
' This Code in its entirety comes courtesy of Lyle Fairfield. It was
downloaded from
' http://ffdba.com/downloads/Send_Mail_With_Outlook_Express.htm
'======================================================================================
Private Type MapiRecip
Reserved As Long
RecipClass As Long
Name As String
ADDRESS As String
EIDSize As Long
EntryID As Long
End Type

Private Type MAPIFileDesc
Reserved As Long
flags As Long
Position As Long
Pathname As String
FileName As String
FileType As Long
End Type

Private Type MAPIMessage
Reserved As Long
Subject As String
NoteText As String
MessageType As String
DateReceived As String
ConversationID As String
Originator As Long
flags As Long
RecipCount As Long
Recipients As Long
FileCount As Long
Files As Long
End Type

Declare Function MAPISendMail _
Lib "c:\program files\outlook express\msoe.dll" ( _
ByVal Session As Long, _
ByVal UIParam As Long, _
Message As MAPIMessage, _
ByVal flags As Long, _
ByVal Reserved As Long) As Long

Public Sub SendMailWithOE(ByVal vSubject As String, _
ByVal vMessage As String, _
ByRef vRecipients As String, _
Optional ByVal vFiles As String)

Dim aFiles() As String
Dim aRecips() As String

Dim FilePaths() As MAPIFileDesc
Dim Recips() As MapiRecip
Dim Message As MAPIMessage

Dim z As Long

aFiles = Split(vFiles, ",")
ReDim FilePaths(LBound(aFiles) To UBound(aFiles))
For z = LBound(aFiles) To UBound(aFiles)
With FilePaths(z)
.Position = -1
.Pathname = StrConv(aFiles(z), vbFromUnicode)
End With
Next z

aRecips = Split(vRecipients, ",")
ReDim Recips(LBound(aRecips) To UBound(aRecips))
For z = LBound(aRecips) To UBound(aRecips)
With Recips(z)
.RecipClass = 1
If InStr(aRecips(z), "@") <> 0 Then
.ADDRESS = StrConv(aRecips(z), vbFromUnicode)
Else
.Name = StrConv(aRecips(z), vbFromUnicode)
End If
End With
Next z

With Message
.FileCount = UBound(FilePaths) - LBound(FilePaths) + 1
.Files = VarPtr(FilePaths(LBound(FilePaths)))
.NoteText = vMessage
.RecipCount = UBound(Recips) - LBound(Recips) + 1
.Recipients = VarPtr(Recips(LBound(Recips)))
.Subject = vSubject
End With
MAPISendMail 0, 0, Message, 0, 0
End Sub


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
Bill,

Are you aware that in the line:

'Dim strTO, ZipName, strSubj, strBody As String'

only 'strBody' was dimmed as a string. All the others were
dimmed as a Variant.

I think you wanted:

Dim strTO As String, ZipName As String
Dim strSubj As String, strBody As String

I don't know if that is your problem but thought you should be
aware of the Dim requirement.

RuralGuy


Bill said:
Dirk,
Below is all the code involved... more than you need, but
shouldn't, hopefully, leave any un-answered questions.

Bill

++++++++++++++(MY CODE)++++++++++++++++++++++++++++++++++++++++++
Option Compare Database
Option Explicit
Dim strTO, ZipName, strSubj, strBody As String 'To who; Zip
file name; e-mail subject; e-mail body text
Dim File1, File2, File3, File4, File5 As Variant 'The file
name and path
Dim F1Sel, F2Sel, F3Sel, F4Sel, F5Sel As String 'Is file
selected for inclusion?
-----------------------------------------------------------------------
---------------- Public Function SendADFData()
Dim WinZip As String
Dim FileList As String
Dim ShellString As Variant

'======================================================================
=== ' First we get our local copies of the distribution parameters.
'======================================================================
=== LoadDistParms

'======================================================================
=== ' Next, we build the list of files to zip
'======================================================================
=== FileList = ""
If F1Sel Then FileList = File1
If F2Sel And Len(File2 & "") > 0 Then FileList = FileList & " " &
File2 If F3Sel And Len(File3 & "") > 0 Then FileList = FileList & " "
& File3 If F4Sel And Len(File4 & "") > 0 Then FileList = FileList & "
" & File4 If F5Sel And Len(File5 & "") > 0 Then FileList = FileList &
" " & File5


'======================================================================
=== ' We use Terry Kreft's ShellWait to Shell to Winzip to zip the ADF
data ' files down to a reasonable size suitable for an e-mail
attachment.
'======================================================================
===

WinZip = "c:\Program Files\Winzip\wzzip.exe"
ShellString = WinZip & " -P " & ZipName & " " & FileList

ShellWait (ShellString)

'======================================================================
=== ' Okay, with our zip file in hand, we now use Lyle Fairfield's
code to ' attach our zip file to an Outlook Express hosted e-mail and
send it to ' whoever is specified in the strTO.
'======================================================================
===

SendMailWithOE strSubj, strBody, strTO, ZipName


End Function
-----------------------------------------------------------------------
----------------------------------- Public Sub LoadDistParms()
Dim con As ADODB.Connection
Dim rsDParms As ADODB.Recordset
Dim rsAtt As ADODB.Recordset
Dim stSQL As String

'======================================================================
==== ' This routine fetches the content of the "Distribution
Parameters" table.
'======================================================================
====

Set con = Application.CurrentProject.Connection

'Open the parameter table.
stSQL = "SELECT * FROM [DistParms]"
Set rsDParms = New ADODB.Recordset
rsDParms.Open stSQL, con, adOpenKeyset, adLockOptimistic

strTO = rsDParms!DistTO
ZipName = rsDParms!DistZIPName
strSubj = rsDParms!DistSubj
strBody = rsDParms!DistBody

F1Sel = rsDParms!DistFile1Sel
File1 = rsDParms!DistFile1

F2Sel = rsDParms!DistFile2Sel
File2 = rsDParms!DistFile2

F3Sel = rsDParms!DistFile3Sel
File3 = rsDParms!DistFile3

F4Sel = rsDParms!DistFile4Sel
File4 = rsDParms!DistFile4

F5Sel = rsDParms!DistFile5Sel
File5 = rsDParms!DistFile5

'Close the properties table recordset.
rsDParms.Close
Set rsDParms = Nothing

Set con = Nothing

End Sub



++++++++++++++(LYLE FAIRFIELD'S
CODE)+++++++++++++++++++++++++++++++++++++ Option Compare Database
'======================================================================
================ ' This Code in its entirety comes courtesy of Lyle
Fairfield. It was downloaded from
' http://ffdba.com/downloads/Send_Mail_With_Outlook_Express.htm
'======================================================================
================ Private Type MapiRecip
Reserved As Long
RecipClass As Long
Name As String
ADDRESS As String
EIDSize As Long
EntryID As Long
End Type

Private Type MAPIFileDesc
Reserved As Long
flags As Long
Position As Long
Pathname As String
FileName As String
FileType As Long
End Type

Private Type MAPIMessage
Reserved As Long
Subject As String
NoteText As String
MessageType As String
DateReceived As String
ConversationID As String
Originator As Long
flags As Long
RecipCount As Long
Recipients As Long
FileCount As Long
Files As Long
End Type

Declare Function MAPISendMail _
Lib "c:\program files\outlook express\msoe.dll" ( _
ByVal Session As Long, _
ByVal UIParam As Long, _
Message As MAPIMessage, _
ByVal flags As Long, _
ByVal Reserved As Long) As Long

Public Sub SendMailWithOE(ByVal vSubject As String, _
ByVal vMessage As String, _
ByRef vRecipients As String, _
Optional ByVal vFiles As String)

Dim aFiles() As String
Dim aRecips() As String

Dim FilePaths() As MAPIFileDesc
Dim Recips() As MapiRecip
Dim Message As MAPIMessage

Dim z As Long

aFiles = Split(vFiles, ",")
ReDim FilePaths(LBound(aFiles) To UBound(aFiles))
For z = LBound(aFiles) To UBound(aFiles)
With FilePaths(z)
.Position = -1
.Pathname = StrConv(aFiles(z), vbFromUnicode)
End With
Next z

aRecips = Split(vRecipients, ",")
ReDim Recips(LBound(aRecips) To UBound(aRecips))
For z = LBound(aRecips) To UBound(aRecips)
With Recips(z)
.RecipClass = 1
If InStr(aRecips(z), "@") <> 0 Then
.ADDRESS = StrConv(aRecips(z), vbFromUnicode)
Else
.Name = StrConv(aRecips(z), vbFromUnicode)
End If
End With
Next z

With Message
.FileCount = UBound(FilePaths) - LBound(FilePaths) + 1
.Files = VarPtr(FilePaths(LBound(FilePaths)))
.NoteText = vMessage
.RecipCount = UBound(Recips) - LBound(Recips) + 1
.Recipients = VarPtr(Recips(LBound(Recips)))
.Subject = vSubject
End With
MAPISendMail 0, 0, Message, 0, 0
End Sub


+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ "Dirk Goldgar said:
Not unless you post your code that declares the arguments and calls
the function.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Bill said:
Dirk,
Below is all the code involved... more than you need, but
shouldn't, hopefully, leave any un-answered questions.

Bill

++++++++++++++(MY CODE)++++++++++++++++++++++++++++++++++++++++++
Option Compare Database
Option Explicit
Dim strTO, ZipName, strSubj, strBody As String
[snip]

In fact, that last line is all I need. VB declarations don't work that
way. In the above Dim statement, only strBody is being declared as
String; the other variables are all declared as Variant. That line is
equivalent to:

Dim strTO
Dim ZipName
Dim strSubj
Dim strBody As String

and that declares all except strBody as the default type, which is
Variant.
 
BINGO!
Thanks,
Bill



Dirk Goldgar said:
Bill said:
Dirk,
Below is all the code involved... more than you need, but
shouldn't, hopefully, leave any un-answered questions.

Bill

++++++++++++++(MY CODE)++++++++++++++++++++++++++++++++++++++++++
Option Compare Database
Option Explicit
Dim strTO, ZipName, strSubj, strBody As String
[snip]

In fact, that last line is all I need. VB declarations don't work that
way. In the above Dim statement, only strBody is being declared as
String; the other variables are all declared as Variant. That line is
equivalent to:

Dim strTO
Dim ZipName
Dim strSubj
Dim strBody As String

and that declares all except strBody as the default type, which is
Variant.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Back
Top