I have an access program that needs to download and load XML data from a site. The code i'm using is below. It is having two problems (and i've tryed a few other syntaxes to save the file...)
1) The Save File dialog box is opening up, even tho i do pass in a path (and i've tried with both one \ and with \) and use FALSE for the second argument...
2) Even when i type the filename manually in the dialog box, it only gives options to save as HTML, not as XML. The file is only understood if it is XML. Note that if i manually use file-save as in the IE window that access has opened in the code above and then save it as xml, the saved file is fine and can be loaded...
Any thoughts on how i can save the correctly opened file as XML successfully?
I'm looking around and see the XML DOM stuff, and that would be able to do it i think, but I don't know how to use these functions on the document object instead of the HTML document which is automatically used for the InternetExplorer.Application Activex Control's document property...
Thanks,
-Ben
*** BEGIN CODE ***
1) The Save File dialog box is opening up, even tho i do pass in a path (and i've tried with both one \ and with \) and use FALSE for the second argument...
2) Even when i type the filename manually in the dialog box, it only gives options to save as HTML, not as XML. The file is only understood if it is XML. Note that if i manually use file-save as in the IE window that access has opened in the code above and then save it as xml, the saved file is fine and can be loaded...
Any thoughts on how i can save the correctly opened file as XML successfully?
I'm looking around and see the XML DOM stuff, and that would be able to do it i think, but I don't know how to use these functions on the document object instead of the HTML document which is automatically used for the InternetExplorer.Application Activex Control's document property...
Thanks,
-Ben
*** BEGIN CODE ***
Private Sub DownloadData_Click()
On Error GoTo Err_DownloadData_Click
Dim IE As Object
Dim URL As String
Dim FileName As String
Dim Password
Password = Me!Password
If IsNull(Password) Or Len(Password) < 1 Then
MsgBox ("Please enter the password for user " & Me!UserName)
Exit Sub
End If
Set IE = CreateObject("InternetExplorer.Application")
URL = Me!DataURL
IE.Navigate URL
IE.Visible = True
While IE.busy
DoEvents 'wait until IE is done loading page.
Wend
IE.Document.All("ilogin").Select
IE.Document.All("ilogin").Value = Me!UserName
IE.Document.All("ipassword").Select
IE.Document.All("ipassword").Value = Me!Password
SendKeys "{ENTER}"
While IE.busy
DoEvents 'wait until IE is done loading page.
Wend
'EVERYTHING WORKS FINE ABOVE
'Save the XML
FileName = Me!DataPath & "\temp.html"
IE.Document.ExecCommand "SaveAs", False, FileName
' THE ABOVE COMMAND OPENS UP THE SAVEAS DIALOG, DOENS"T SAVE AUTOMATICALLY, AND THEN EVEN IF YOU USE THAT IT"S SAVED AS HTML NOT XML.
'SendKeys "{ENTER}"
While IE.busy
DoEvents 'wait until IE is done loading page.
Wend
Exit_DownloadData_Click:
Exit Sub
Err_DownloadData_Click:
MsgBox err.Description
Resume Exit_DownloadData_Click
End Sub
On Error GoTo Err_DownloadData_Click
Dim IE As Object
Dim URL As String
Dim FileName As String
Dim Password
Password = Me!Password
If IsNull(Password) Or Len(Password) < 1 Then
MsgBox ("Please enter the password for user " & Me!UserName)
Exit Sub
End If
Set IE = CreateObject("InternetExplorer.Application")
URL = Me!DataURL
IE.Navigate URL
IE.Visible = True
While IE.busy
DoEvents 'wait until IE is done loading page.
Wend
IE.Document.All("ilogin").Select
IE.Document.All("ilogin").Value = Me!UserName
IE.Document.All("ipassword").Select
IE.Document.All("ipassword").Value = Me!Password
SendKeys "{ENTER}"
While IE.busy
DoEvents 'wait until IE is done loading page.
Wend
'EVERYTHING WORKS FINE ABOVE
'Save the XML
FileName = Me!DataPath & "\temp.html"
IE.Document.ExecCommand "SaveAs", False, FileName
' THE ABOVE COMMAND OPENS UP THE SAVEAS DIALOG, DOENS"T SAVE AUTOMATICALLY, AND THEN EVEN IF YOU USE THAT IT"S SAVED AS HTML NOT XML.
'SendKeys "{ENTER}"
While IE.busy
DoEvents 'wait until IE is done loading page.
Wend
Exit_DownloadData_Click:
Exit Sub
Err_DownloadData_Click:
MsgBox err.Description
Resume Exit_DownloadData_Click
End Sub