Open InfoPath from Access

C

chrismahoney

Hi

I'm moving an old Outlook form across to InfoPath, and I'm trying to
figure out how to open the form from Access. This is the current code:

Dim objOutlook As Outlook.Application
Dim nsOutlook As Outlook.NameSpace
Dim folTask As Object
Dim tskPhoto As Outlook.MailItem

Set objOutlook = New Outlook.Application
Set nsOutlook = objOutlook.GetNamespace("MAPI")
Set folTask = nsOutlook.GetDefaultFolder(olFolderInbox)
Set tskPhoto = folTask.Items.Add("IPM.Note.library Photos")

With tskPhoto
.UserProperties.Item("FilmNumber").Value = filmNumber
.UserProperties.Item("StaffNumber").Value = StaffNumber
.Subject = "Please enter the relevant information for each photo in
the 'Photos' form"
.Body = " "
.ReminderSet = True
.ReminderTime = DateAdd("d", 6, Date) & " 12:00:00"
End With
Call tskPhoto.Recipients.Add(StaffName)
Call tskPhoto.Send

I didn't write this code, but it appears to be passing two variables
(FilmNumber and StaffNumber) into the Outlook form. I've created a
couple of fields in InfoPath for these variables to go into, but I have
no idea how to modify the above code to use InfoPath instead of
Outlook.

Help please :)

Thanks
Chris
 
C

chrismahoney

I've tried a few things, and so far I have this:

Dim objInfoPath As New InfoPath.Application
objInfoPath.XDocuments.Open Application.CurrentProject.Path &
"\LibraryPhotos.xsn"
objInfoPath.XDocuments(0).DOM.selectSingleNode("//my:FilmNumber").Text
= filmNumber

Am I on the right track? That code fails on the .Open line, with the
following message:

Run-time error '-2147209207 (80043009)':
InfoPath cannot open the following file: LibraryPhotos.xsn.
The file is not a valid XML file.
??
The form contains XML that cannot be parsed:
An invalid character was found in text content.
Line 1. Position 5

I've taken a look at line 1 pos 5 but it appears blank (like a space)
in Notepad. I suppose it could be a hidden character though, as after
all it's a binary file (first 4 bytes are "MSCF", as you'd expect from
a Microsoft Cabinet File). I thought maybe I need to decompress the XSN
first, but that didn't help. I do get a slightly different message
though:

Run-time error '-2147209148 (80043044)':
InfoPath cannot open the following file: manifest.xsf.
The file does not appear to be an InfoPath form.
??
The processing instruction in the file is missing or invalid.

I've also tried opening the template.xml file, but I get an
"Insufficient Security Privilege" message.

Presumably it's my code that's wrong, rather than the XSN/XSF/XML
files. Can anyone give me any pointers?

Thanks
Chris
 
C

chrismahoney

Success... sort of.

The following code works:

Dim objInfoPath As New InfoPath.Application
objInfoPath.XDocuments.NewFromSolution
"\\Jupiter\ChrisMa\Settings\Desktop\LibraryPhotos.xsn"
objInfoPath.XDocuments(0).DOM.selectSingleNode("//my:FilmNumber").Text
= filmNumber

Of course, I don't want an absolute path in there, so I changed the
second line to:

objInfoPath.XDocuments.NewFromSolution Application.CurrentProject.Path
& "\LibraryPhotos.xsn"

Unfortunately, this fails.

Run-time error '-2147209000 (800430d8)':
InfoPath cannot create a new, blank form.
InfoPath cannot open the form. To fix this problem, contact your
system administrator.
??
Form template: D:\Databases\Library\LibraryPhotos.xsn
The selected file is an update of a form on your computer. However,
the update has been blocked because the author of the file cannot be

The message just stops there, the end of it has been cut off. Any ideas
what it's trying to say, or how to get around it?

Thanks
Chris
 
R

renee rieser

Chris,

I'm just taking a stab here, but with the infopath form in design
mode, go to tools/form options/security and uncheck the "auto
determine security" checkbox and change it to "Domain" security.

Republish the infopath form and then try again.

Renee
 
C

Chris

I've run into another problem now. I have the following code in Access:

Dim objInfoPath As New InfoPath.Application
objInfoPath.XDocuments.NewFromSolution Application.CurrentProject.Path
& "\LibraryPhotos.xsn"
objInfoPath.XDocuments(0).DOM.selectSingleNode("//my:FilmNumber").Text
= filmNumber

And the following in InfoPath:

Sub msoxd_my_FilmNumber_OnAfterChange(eventObj)
If eventObj.IsUndoRedo Then
Exit Sub
End If
Dim MainAdapter
Dim FilmNumber
Set MainAdapter = XDocument.DataAdapters("Main connection")
FilmNumber = XDocument.DOM.selectSingleNode("//my:FilmNumber").text
MainAdapter.Command = "SELECT * FROM tblPHOTO_CATALOG WHERE
PHO_film_number = '" & FilmNumber & "' ORDER BY PHO_photo_number;"
MainAdapter.Query
End Sub

Independently, they work fine. The Access code correctly opens the
database and puts the filmNumber variable into the my:FilmNumber text
box. The InfoPath code correctly requeries whenever you change the film
number.

The problem occurs when both subs are present. When running the code in
Access, InfoPath pops up and displays the form for a split-second, then
the my:FilmNumber box updates and BAM! My repeating section disappears.
I can't understand why this is happening, because as I said above, the
two sections of code work perfectly on their own.

As for the form itself, I have one big repeating section containing
everything except for the my:FilmNumber box. I've tried putting
my:FilmNumber inside the repeating section, but there is no difference.
I've also tried pulling other controls out of the repeating section,
that doesn't help either (they still disappear).

Any ideas?

Thanks
Chris
 
C

Chris

I haven't changed anything, but it's working now. I'm so confused.

I wonder if maybe it has something to do with the conflict I got a few
minutes ago, see my new topic "Form Conflict" for the details.

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top