By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,122 Members | 921 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,122 IT Pros & Developers. It's quick & easy.

VBA - XML SelectSingleNode - Syntax Problem

P: 4
Refs - See attached images.



My XML file structure is a config file: It works fine

Simply trying to change date between the quotes of "2017-05-10" 'in the StartDate value to 2017-05-11

see attached image for the pop up err on bold line in code

My code I Have so far.
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <configuration>
  3.   <configSections>
  4.      ...some xml struc
  5.   </configSections>
  6.  
  7.   <appSetttings>
  8.      <add key="xxx" value="yyy" />
  9.      <add key="xxx" value="www" />
  10.      <add key="StartDate" value="2017-05-10" />
  11.      <add key="EndDate" value="2017-05-25" />
  12.      <add key="zzz" value="nnn" />
  13.   </appSettings> 
  14.  
  15.  etc
  16.  
  17. </configuration>
  18.  
  19. 'Access VBA 2010
  20.  
  21. Dim wXML As Object, xFile As String
  22.  
  23. Set wXML = CreateObject("Microsoft.XMLDOM")
  24.  
  25. xFile = "C:\CTI Group\ArchiveClientTools\v2-0-0\ArchiveClientTools\SRIPArchiveClientForm.exe.config"
  26.  
  27. wXML.Load (xFile)
  28.  
  29. 'errs here.
  30.  
  31. wXML.documentElement.SelectSingleNode("configuration/appSettings/add key/[@Name='StartDate']/value").InnerText = "2017-05-11"
No joy. Am I missing something simple?

Thanks. :o)
Attached Images
File Type: jpg err.jpg (17.6 KB, 404 views)
File Type: jpg refs.jpg (55.9 KB, 338 views)
May 28 '17 #1

✓ answered by CJames

With a little help we got it figured out... Easy in hindsight... not so looking forward before it worked...

*************************************
Expand|Select|Wrap|Line Numbers
  1. Dim wXML As Object, xFile As String
  2.     Set wXML = CreateObject("Microsoft.XMLDOM")
  3.     xFile = "C:\CTI Group\ArchiveClientTools\v2-0-0\ArchiveClientTools\SRIPArchiveClientForm.exe.config"
  4.  
  5.     If wXML.Load(xFile) Then
  6.         wXML.DocumentElement.SelectSingleNode("//add[@key=""StartDate""]").setAttribute "value", "2017-05-11"
  7.         wXML.Save xFile
  8.     Else
  9.         MsgBox wXML.parseError.reason, , wXML.parseError.ErrorCode
  10.     End If
  11.  
  12.     Set wXML = Nothing

Share this Question
Share on Google+
2 Replies


P: 4
With a little help we got it figured out... Easy in hindsight... not so looking forward before it worked...

*************************************
Expand|Select|Wrap|Line Numbers
  1. Dim wXML As Object, xFile As String
  2.     Set wXML = CreateObject("Microsoft.XMLDOM")
  3.     xFile = "C:\CTI Group\ArchiveClientTools\v2-0-0\ArchiveClientTools\SRIPArchiveClientForm.exe.config"
  4.  
  5.     If wXML.Load(xFile) Then
  6.         wXML.DocumentElement.SelectSingleNode("//add[@key=""StartDate""]").setAttribute "value", "2017-05-11"
  7.         wXML.Save xFile
  8.     Else
  9.         MsgBox wXML.parseError.reason, , wXML.parseError.ErrorCode
  10.     End If
  11.  
  12.     Set wXML = Nothing
May 29 '17 #2

NeoPa
Expert Mod 15k+
P: 31,419
Glad to see you got it sorted without help. I'm very unfamiliar with all the XML stuff unfortunately.
May 30 '17 #3

Post your reply

Sign in to post your reply or Sign up for a free account.