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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What could be wrong wit this ?

Status
Not open for further replies.

JonEx

Programmer
Joined
Feb 26, 2004
Messages
21
Location
BB
Hey,
ok i have a form that automates outlook , it has a subject and a message body the only problem i have to face now is how to add an attachment field in the form as well.

ive tried some stuff but i get this error
One or More parameter values are not valid.
can anyone examine this code and see where i went wrong.

code for command button to send email
************************************************************
Private Sub cmdSend_Click()
On Error GoTo Err_cmdSend_Click

Dim lngCurrentRow As Integer
Dim strTo As String
Dim strCC As String
Dim strBCC As String
Dim strAttach As String
Dim bOK As Boolean

If Me.Subject = STR_NULL1 Or IsNull(Me.Subject) Then
MsgBox "You have not entered a valid subject.",
vbCritical + vbOKOnly, "Error"
Exit Sub
End If

If Me.MessageText = STR_NULL1 Or IsNull(Me.MessageText)Then
MsgBox "You have not entered a valid message.", vbCritical + vbOKOnly, "Error"
Exit Sub
End If

strAttach = txtAttachment
If Me.txtAttachment = STR_NULL1 Or IsNull(Me.txtAttachment) Then
MsgBox "Note you did not attach any files.", vbOKOnly
Exit Sub
End If

For lngCurrentRow = 0 To lstTo.ListCount - 1
If lngCurrentRow = 0 Then
strTo = lstTo.Column(0, lngCurrentRow)
Else
strTo = strTo & ";" & lstTo.Column(0, lngCurrentRow)
End If
Next lngCurrentRow

If strTo = STR_NULL1 Or IsNull(strTo) Then
MsgBox "You have not entered a valid recipient address.", vbCritical + vbOKOnly, "Error"
Exit Sub
End If

For lngCurrentRow = 0 To lstCC.ListCount - 1
If lngCurrentRow = 0 Then
strCC = lstCC.Column(0, lngCurrentRow)
Else
strCC = strCC & ";" & lstCC.Column(0, lngCurrentRow)
End If
Next lngCurrentRow

For lngCurrentRow = 0 To lstBCC.ListCount - 1
If lngCurrentRow = 0 Then
strBCC = lstBCC.Column(0, lngCurrentRow)
Else
strBCC = strBCC & ";" & lstTo.Column(0, lngCurrentRow)
End If
Next lngCurrentRow

Call SendMsg(Me.Subject, Me.MessageText, strTo, strCC, strBCC, strAttach)

Exit_cmdSend_Click:
Exit Sub

Err_cmdSend_Click:
MsgBox err.Description
Resume Exit_cmdSend_Click

End Sub
************************************************************
code for the attachment button

************************************************************
Private Sub cmdBrowse_Click()
On Error GoTo err_cmdBrowse

Me.txtAttachment = GetOpenFile_CLT("C:\", "Select a File to Attach.")
Me.txtAttachment = LCase(Me.txtAttachment)

If Me.txtAttachment <> STR_NULL1 And Not IsNull(Me.txtAttachment) Then
Me.txtAttachmentAlias.Enabled = True
Me.txtAttachmentAlias.SetFocus
Else
Me.txtAttachmentAlias.Enabled = False
End If

exit_cmdBrowse:
Exit Sub

err_cmdBrowse:
MsgBox err.Description
Resume exit_cmdBrowse
End Sub

************************************************************
code for module that has function GetOpenFile_CLT
Function GetOpenFile_CLT(strInitialDir As String, strTitle As String) As String
' Comments : Simple file open routine. For additional options, use GetFileOpenEX_CLT()
' Parameters: strInitialDir - path for the initial directory, or blank for the current directory
' strTitle - title for the dialog
' Returns : string path, name and extension of the file selected
'
Dim fOK As Boolean
Dim typWinOpen As CLTAPI_WINOPENFILENAME
Dim typOpenFile As CLTAPI_OPENFILE
Dim strFilter As String

On Error GoTo PROC_ERR

' Set reasonable defaults for the structure
strFilter = CreateFilterString_CLT("All Files (*.*)", "*.*")

If strInitialDir <> "" Then
typOpenFile.strInitialDir = strInitialDir
Else
typOpenFile.strInitialDir = CurDir()
End If

If strTitle <> "" Then
typOpenFile.strDialogTitle = strTitle
End If

typOpenFile.strFilter = strFilter
typOpenFile.lngFlags = OFN_HIDEREADONLY Or OFN_SHOWHELP

' Convert the CLT structure to a Win structure
ConvertCLT2Win typOpenFile, typWinOpen

' Call the Common dialog
fOK = CLTAPI_GetOpenFileName(typWinOpen)

' Convert the Win structure back to a CLT structure
ConvertWin2CLT typWinOpen, typOpenFile

GetOpenFile_CLT = typOpenFile.strFullPathReturned

PROC_EXIT:
Exit Function

PROC_ERR:
GetOpenFile_CLT = ""
Resume PROC_EXIT

End Function

************************************************************
module code for automation of outlook
************************************************************
Public Sub SendMsg(strSubject As String, _
strBody As String, _
strTo As String, _
strAttach As String, _
Optional strCC As String = STR_NULL1, _
Optional strBCC As String = STR_NULL1)

Dim oLapp As Outlook.Application
Dim oItem As Outlook.MailItem

strAttach = txtAttachments
Set oLapp = CreateObject("Outlook.Application")
Set oItem = oLapp.CreateItem(0)
With oItem
.Subject = strSubject
.To = strTo
.Attachments = strAttach

If Not IsMissing(strCC) And strCC <> STR_NULL1 Then
.CC = strCC
End If
If Not IsMissing(strBCC) And strBCC <> STR_NULL1 Then
.BCC = strBCC
End If
.Body = strBody

.Send

End With
Set oLapp = Nothing
Set oItem = Nothing

End Sub

************************************************************
thats it .. would really appreciate some help with this one

thankz,
Jonex
 
In your SendMsg sub ... remove the line that has

strAttach = txtAttachments

You haven't passed any variable named txtAttachments to the subroutine, and Access isn't going to know what txtAttachments is since that variable is not in the scope of the subroutine.

Simply remove the assignment statement in your code and it should work correctly.


Greg Tammi, IT Design & Consultation
Work: Home:
 
hey thanks grtammi,
but it still didnt work, access came up with this error ... the system cannot find the path specified..
what would i have to change ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top