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
chrismahoney@gmail.com - 21 Mar 2006 05:22 GMT
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
renee rieser - 21 Mar 2006 20:06 GMT
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
>InfoPath cannot create a new, blank form
chrismahoney@gmail.com - 21 Mar 2006 21:08 GMT
That did it! Thanks! :)
Chris - 21 Mar 2006 23:03 GMT
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
Chris - 23 Mar 2006 21:47 GMT
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