Hi,
I've posted a thread concerning this before but I didn't really get an answer and now I've narrowed down the problem.
When I use ShellExecute to create a new message in Outlook, I pass it a string variable that contains "mailto:" and whatever email addresses have been added to that variable.
Sometimes the variable will have enough addresses in it to be over 255 charcters long. When you check the debug window, you can't see past 255 characters in the value part of the variable but a debug.print statement in the immediate window confirms that the data is all present and correct.
However, when I pass this string to Outlook, it only accepts 255 characters of the string, so not all of the addresses appear in the To: part of the new message window and the last address that appears is usually cut off half way through.
I thought that perhaps the To: textbox has a limit of 255 characters but it's possible to manually carry on typing into it and finish off the addresses.
This, as you can imagine, is my problem. Does anyone know why this is happening? Has anyone had a similar problem? I'm pretty sure that this shouldn't be happening and my code doesn't seem complex enough to cause an unexpected error, just incase it is causing it though, I present it below:
Private Sub frmMassEmailButton_Click()
'qdf - Used to represent the query qryMassEmail.
'rs - Used to represnt the recordset generated by qryMassEmail.
Dim db As DAO.Database, rs As DAO.Recordset, qdf As DAO.QueryDef
'sText - Used to hold the "mailto:" text string.
Dim sText As String
Set db = CurrentDb
Set qdf = db.QueryDefs("qryMassEmail"
'Set the three parameters in the query.
qdf![Forms!frmMassEmail!CCode] = Forms![frmMassEmail]![CCode]
qdf![Forms!frmMassEmail!CoDate] = Nz(Forms![frmMassEmail]![CoDate], "*"
qdf![Forms!frmMassEmail!Status] = Nz(Forms![frmMassEmail]![Status], "*"
Set rs = qdf.OpenRecordset()
With rs
Do While Not rs.EOF
'If this is the first email address...
If Len(sText) = 0 Then
'...If an Email Address does exist and it's not equal to "Not Set"...
If Len(![EMail Address]) And Not (![EMail Address] = "Not Set"
Then
'...add the first address to the string.
sText = "mailto:" & ![EMail Address]
End If
'Otherwise this is not the first email address to be added.
Else
If Len(![EMail Address]) And Not (![EMail Address] = "Not Set"
Then
'Add the new address on to the end of the sText.
sText = sText & "; " & ![EMail Address]
End If
End If
'Move to the next record in the recordset.
.MoveNext
Loop
End With
'If sText has email addresses...
If Len(sText) Then
'...launch default e-mail program
Call ShellExecute(Me.hwnd, "open", sText, vbNullString, vbNullString, 0)
'If the user didn't enter a status of an employee to search for...
ElseIf IsNull(Me.Status) Then
MsgBox ("There are no employees with any status"
& _
" for this course on " & Nz(Me.CoDate, "any date"
Else
MsgBox ("There are no employees with status '" & Me.Status) & _
"' for this course on " & Nz(Me.CoDate, "any date"
& "."
End If
End Sub
Here's ShellExecute, I believe I got i off this site somewhere, possibly in a FAQ.
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Hope somebody can help, thanks a lot.
Cheers,
Pete
I've posted a thread concerning this before but I didn't really get an answer and now I've narrowed down the problem.
When I use ShellExecute to create a new message in Outlook, I pass it a string variable that contains "mailto:" and whatever email addresses have been added to that variable.
Sometimes the variable will have enough addresses in it to be over 255 charcters long. When you check the debug window, you can't see past 255 characters in the value part of the variable but a debug.print statement in the immediate window confirms that the data is all present and correct.
However, when I pass this string to Outlook, it only accepts 255 characters of the string, so not all of the addresses appear in the To: part of the new message window and the last address that appears is usually cut off half way through.
I thought that perhaps the To: textbox has a limit of 255 characters but it's possible to manually carry on typing into it and finish off the addresses.
This, as you can imagine, is my problem. Does anyone know why this is happening? Has anyone had a similar problem? I'm pretty sure that this shouldn't be happening and my code doesn't seem complex enough to cause an unexpected error, just incase it is causing it though, I present it below:
Private Sub frmMassEmailButton_Click()
'qdf - Used to represent the query qryMassEmail.
'rs - Used to represnt the recordset generated by qryMassEmail.
Dim db As DAO.Database, rs As DAO.Recordset, qdf As DAO.QueryDef
'sText - Used to hold the "mailto:" text string.
Dim sText As String
Set db = CurrentDb
Set qdf = db.QueryDefs("qryMassEmail"
'Set the three parameters in the query.
qdf![Forms!frmMassEmail!CCode] = Forms![frmMassEmail]![CCode]
qdf![Forms!frmMassEmail!CoDate] = Nz(Forms![frmMassEmail]![CoDate], "*"
qdf![Forms!frmMassEmail!Status] = Nz(Forms![frmMassEmail]![Status], "*"
Set rs = qdf.OpenRecordset()
With rs
Do While Not rs.EOF
'If this is the first email address...
If Len(sText) = 0 Then
'...If an Email Address does exist and it's not equal to "Not Set"...
If Len(![EMail Address]) And Not (![EMail Address] = "Not Set"
'...add the first address to the string.
sText = "mailto:" & ![EMail Address]
End If
'Otherwise this is not the first email address to be added.
Else
If Len(![EMail Address]) And Not (![EMail Address] = "Not Set"
'Add the new address on to the end of the sText.
sText = sText & "; " & ![EMail Address]
End If
End If
'Move to the next record in the recordset.
.MoveNext
Loop
End With
'If sText has email addresses...
If Len(sText) Then
'...launch default e-mail program
Call ShellExecute(Me.hwnd, "open", sText, vbNullString, vbNullString, 0)
'If the user didn't enter a status of an employee to search for...
ElseIf IsNull(Me.Status) Then
MsgBox ("There are no employees with any status"
" for this course on " & Nz(Me.CoDate, "any date"
Else
MsgBox ("There are no employees with status '" & Me.Status) & _
"' for this course on " & Nz(Me.CoDate, "any date"
End If
End Sub
Here's ShellExecute, I believe I got i off this site somewhere, possibly in a FAQ.
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Hope somebody can help, thanks a lot.
Cheers,
Pete