Coding Multiple Variable Attachments for Appointments in VBA

  • Thread starter Thread starter Joe Jacobs
  • Start date Start date
J

Joe Jacobs

Hello! I am attempting to code a routine that originates Outlook
appointments from within an Access 2K database. Although I have no problem
coding for the basic appointment parameters, I am having trouble with the
attachments.

BACKGROUND -- I have built a project management database that contains a
group of forms dedicated to training. Within this group, the user can
designate attendees, resources, and documents that will be used to schedule
subsequent training sessions. Paths to the documents are stored in
tblProcessDocs. Only those docs linked to the primary key of the training
record are available for attachment to the appointment.

When I attempt to attach the documents, however, I receive the following
error: "File name or directory name is not valid." (NOTE: Error number
changes depending upon the file selected, but the description remains
consistent.)

HOW IT WORKS: In the routine (code below), I set the basic parameters for
the appointment, assign recipients, and assign resources. Then I create a
snapshot recordset and determine if the main training record contains any
process document subrecords. If true, then I run an attachment loop. Within
this loop, I open an attachment form as a dialog that displays all the
documents available for the training sessions. On clicking a command button,
the doc path is placed in a public variable that is then used in the
..Attachments.Add(DocPath) method. This loop then repeats until the user
closes the attachment dialog, which sets a additional public variable to
True. In short, the user can add any number of attachments, any one of which
may be different depending upon the training session to which it is linked.

CODE:Public myDocLink As String
Public myAttachedFlag As Boolean
Private Sub cmdAttachApptDoc_Click()
myDocLink = Me.DocPath.Value
DoCmd.Close
End Sub

Private Sub cmdCloseApptAttachForm_Click()
myAttachedFlag = True
DoCmd.Close
End Sub
Dim myPath as String
...

Set myAttendeeBase = CurrentDb
Set myAttendeeSet = myAttendeeBase.OpenRecordset("SELECT
tblProcessDocs.DocPath FROM tblProcessDocs WHERE
(((tblProcessDocs.TrainingID)= " & myAttendeeID & "));", dbOpenSnapshot)

If myAttendeeSet.RecordCount > 0 Then
Do While myAttachedFlag = False
DoCmd.OpenForm "frmProcessDocsTrainingAttachments", , , , ,
acDialog
myPath = """" & myDocLink & """"
Debug.Print myPath
Set myApptAttachments = objAppt.Attachments.Add(myPath)
Loop
End If
The Immediate window shows the following string for myPath:
"C:\Documents and Settings\z035238\My Documents\Data Sources in InfoPath.pdf"

Given this, I do not understand why I am receiving the error noted above.
Although I am new to VBA, I have scoured the newsgroups here at MSDN and
other sites to find an answer on my own. Having failed, I'm reaching out for
more explicit help. Thanks in advance!!!
 
Adding myDocLink should be fine, probably in myPath there're too many "".

--
Best regards
Michael Bauer - MVP Outlook

: VBOffice Reporter for Data Analysis & Reporting
: Outlook Categories? Category Manager Is Your Tool
: <http://www.vboffice.net/product.html?pub=6&lang=en>


Am Mon, 21 Jul 2008 08:41:01 -0700 schrieb Joe Jacobs:
 
Back
Top