troubleshooting Question

Can someone please explain to me what value or object is needed in this code MS Access VBA.

Avatar of Dustin Stanley
Dustin Stanley asked on
Microsoft AccessVBA
8 Comments1 Solution148 ViewsLast Modified:
I have been looking for a way to parse a MIME. I found this site that has a reference library for Access just for what I am looking for. It costs but if it works I may take it.

MIME being Parsed:
Content-Type: multipart/mixed;
 boundary="------------080707010302060306060800";

This is a multi-part message in MIME format.

--------------080707010302060306060800
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

This is the plain-text body.
--------------080707010302060306060800
Content-Disposition: attachment; filename="starfish.gif";
Content-Transfer-Encoding: base64
Content-Type: image/gif; name="starfish.gif";

R0lGODlhIAAgAPcAAP///+/v7/f39+/n5/fv7//39/fn597OzufW1tbGxs69vffe3u/W1salpZQQ
EIQYEJwQCJQYCJwYCM6clL2Ee5wpGIwhEK0YANatpdalnHMYCKUhCJQYAKUYAM6Ec5QhCJwhCPfW
zu/Oxta1rb17a6UhAK0hAPe9rb2Ec7V7a71rUpwpCL0xCJwhAOfOxta9tcatpdallM6cjMaUhK1C
IZwxELU5EK0xCLUxCN61pcacjK1rUrVaOaVKKZxCIZwxCKUxCL05CLUxAM6llO+1nMZzUr1rSrVS
KaVCGK1CGLVCEJQxCK05CLU5CIwpAKUxAK0xAM69tffWxrVrSrVaMbVKGMZKEL1CCLU5AP/v597O
xufGtcallNaljLWEa96ce9aUc717Wq1aMcZjMbVaKbVSIa1KGL1SGJw5CK1CCLVCCMZKCM5KCMZC
APfn3tbGvc57Ss5aGMZSENZaEL1KCM5SCLVCAMZKAPfezvfOte/GrdatlN6cc9aEUr1rOc5jIdZj
GL1SEM5aELVKCMZSCNZaCL1KAOfOvc57Qs5jGNZjEM5aCMZSAN5aAO/OtefGrcZjGM5jEN5rELVS
CMZaCN5jCOdrCM5aAO/Gpc5rGMZjENZrEN5jAOdrAOfe1t6MQtZ7Kd57IdZzGM5rEMZjCNZrCM5j
ANbOxu/Wve+9jPe9hO+1e+etc85zGO+EGMZrENZzEM5rCN5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QAA7

--------------080707010302060306060800--


The Actual Code:
Dim mime As New ChilkatMime

Dim success As Long
success = mime.UnlockComponent("Anything for 30-day trial.")
If (success = 0) Then
    Text1.Text = Text1.Text & mime.LastErrorText & vbCrLf
    Exit Sub
End If

'  Load the sampleMime2.txt file into the MIME object.
'  (This file is available at http://www.chilkatsoft.com/testData/sampleMime2.txt )

success = mime.LoadMimeFile("sampleMime2.txt")
If (success = 0) Then
    Text1.Text = Text1.Text & mime.LastErrorText & vbCrLf
    Exit Sub
End If

'  The GIF image is the 2nd sub-part located directly under the
'  top-level MIME node.  Indexing begins at 0, therefore the 2nd
'  sub-part is at index 1.
Dim part2 As ChilkatMime
Set part2 = mime.GetPart(1)

Dim binaryData() As Byte

'  The GetBodyBinary method returns the binary bytes
'  of the part's body, automatically decoded from whatever
'  content-transfer-encoding might be used (such as base64).
binaryData = part2.GetBodyBinary()

'  We now have the binary bytes of the GIF image in binaryData.
'  Save it to a file.
Dim fac As New CkFileAccess
success = fac.WriteEntireFile("out1.gif",binaryData)
If (success <> 1) Then
    Text1.Text = Text1.Text & fac.LastErrorText & vbCrLf
    Exit Sub
End If

'  An easier way to save the body content to a file,
'  assuming your application does not need to access
'  the binary data in-memory, is to call SaveBody
success = part2.SaveBody("out2.gif")
If (success = 0) Then
    Text1.Text = Text1.Text & part2.LastErrorText & vbCrLf
    Exit Sub
End If

Text1.Text = Text1.Text & "Finished." & vbCrLf


What are they looking for with "Text1.Text = Text1.Text"?????


What is "Text1.Text"???


When I send for the API I use "reader.responseText" or "reader.responseXML"
Dim reader As New MSXML2.XMLHTTP40


Is this what it needs "reader.responseText"?

If so it says Compile Error: Can't assign to read-only property.

This is the website the code came from:
https://www.example-code.com/vb/mime_extractBinaryData_a.asp


Here is my complete code I am using:

Public Function EbayDownloadFile()
    Dim reader As New MSXML2.XMLHTTP40
    Dim Doc As New MSXML2.DOMDocument
    Dim TokenValue As String
    Dim APICALL As String
    Dim DevName As String
    Dim AppName As String
    Dim CertName As String
    On Error GoTo ErrorHandler1
    
    TokenValue = Forms!frmEbayTokenCode!txtTokenCode ' This is used for the Token Code insert manually on the Form Ebay Add Fixed Price Item.
    DevName = Forms!frmEbayTokenCode!txtDevName 'Supplied by ebay.
    AppName = Forms!frmEbayTokenCode!txtAppName 'Supplied by ebay.
    CertName = Forms!frmEbayTokenCode!txtCertName 'Supplied by ebay.
    
    
    APICALL = "downloadFile"
    
    Doc.Load "C:\Users\Station\Documents\Access XML Save Files\New Testing\downloadFile.xml" 'Document Location of the XML File With Items Being Added

    
    reader.Open "POST", "https://storage.sandbox.ebay.com/FileTransferService", False
    reader.setRequestHeader "X-EBAY-SOA-OPERATION-NAME", APICALL
    reader.setRequestHeader "X-EBAY-SOA-SECURITY-TOKEN", TokenValue
    reader.setRequestHeader "X-EBAY-API-DETAIL-LEVEL", "0"
    reader.setRequestHeader "X-EBAY-API-COMPATIBILITY-LEVEL", "967"
    reader.setRequestHeader "X-EBAY-API-SITEID", "0"
    reader.setRequestHeader "X-EBAY-API-DEV-NAME", DevName
    reader.setRequestHeader "X-EBAY-API-APP-NAME", AppName
    reader.setRequestHeader "X-EBAY-API-CERT-NAME", CertName
    
    
    reader.send Doc 'This sends the XML document from above.
    Do Until reader.ReadyState = 4
        DoEvents
    Loop
    
    'Get the server's response
    sResponse = reader.responseText
    
     SaveStringAsTextFile "C:\Users\Station\Documents\Access XML Save Files\New Testing\ebay_StartJobRequest_response_File.txt", sResponse
    
'**********************************************************************************************************************************************************
'ChilKat Code Start
'**********************************************************************************************************************************************************

Dim mime As New ChilkatMime
Dim success As Long
success = mime.UnlockComponent("Anything for 30-day trial.")
If (success = 0) Then
    reader.responseText = reader.responseText & mime.LastErrorText & vbCrLf
    Exit Function
End If

'  Load the sampleMime2.txt file into the MIME object.
'  (This file is available at http://www.chilkatsoft.com/testData/sampleMime2.txt )

success = mime.LoadMimeFile("C:\Users\Station\Documents\Access XML Save Files\New Testing\ebay_StartJobRequest_response_File.txt")
If (success = 0) Then
    reader.responseText = reader.responseText & mime.LastErrorText & vbCrLf
    Exit Function
End If

'  The GIF image is the 2nd sub-part located directly under the
'  top-level MIME node.  Indexing begins at 0, therefore the 2nd
'  sub-part is at index 1.
Dim part2 As ChilkatMime
Set part2 = mime.GetPart(1)

Dim binaryData() As Byte

'  The GetBodyBinary method returns the binary bytes
'  of the part's body, automatically decoded from whatever
'  content-transfer-encoding might be used (such as base64).
binaryData = part2.GetBodyBinary()

'  We now have the binary bytes of the GIF image in binaryData.
'  Save it to a file.
Dim fac As New CkFileAccess
success = fac.WriteEntireFile("C:\Users\Station\Documents\Access XML Save Files\New Testing\ChilKat1.gz", binaryData)
If (success <> 1) Then
    reader.responseText = reader.responseText & fac.LastErrorText & vbCrLf
    Exit Function
End If

'  An easier way to save the body content to a file,
'  assuming your application does not need to access
'  the binary data in-memory, is to call SaveBody
success = part2.SaveBody("C:\Users\Station\Documents\Access XML Save Files\New Testing\ChilKat2.gz")
If (success = 0) Then
    reader.responseText = reader.responseText & part2.LastErrorText & vbCrLf
    Exit Function
End If

reader.responseText = reader.responseText & "Finished." & vbCrLf
    
    Exit Function
    
ErrorHandler1:
        MsgBox "Error " & Err.Number & ": " & Err.Description & " in " & _
   VBE.ActiveCodePane.CodeModule, vbOKOnly, "ErrorHandler1"
    Set reader = Nothing
End Function



Public Sub SaveStringAsTextFile(psPathFile As String, psFileContents)
'160730 strive4peace
   Dim iFile As Integer
   On Error GoTo ErrorHandler4
   
   iFile = FreeFile
   Open psPathFile For Output As iFile
   Print #iFile, psFileContents
   Close iFile
   
   Exit Sub
    
ErrorHandler4:
        MsgBox "Error " & Err.Number & ": " & Err.Description & " in " & _
   VBE.ActiveCodePane.CodeModule, vbOKOnly, "ErrorHandler4"
    Set reader = Nothing
    Set strmImage = Nothing
    Set objNode = Nothing
    Set objXML = Nothing

End Sub


Thanks for the help!
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros