How to connect to a web-API enabled database via VBA

Said El Noshokaty 1 Reputation point
2021-12-26T16:34:42.693+00:00

Hi All,

I'm trying to use the following subroutine I found on the internet to connect from an Access (2016 64 bit) database to another web-API enabled Access (2016 64 bit) database to extract some data elements:

Sub DownloadFile0()

Dim Stm As ADODB.Stream
Dim Rec As New ADODB.Record
Dim Conn As New ADODB.Connection
Dim Url As String, Str As String

Url = "http://URL/sosdata.accdb/sdr/doll_per_sdr" ' URL followed by the database, record, and field names

Conn.Provider = "Microsoft.ACE.OLEDB.12.0,DataSource"
Conn.Open Url
Rec.Open Url, Conn
Set Stm = Rec.Fields(adDefaultStream).Value
Str = Stm.ReadText
...

Conn.Close
Rec.Close
Stm.Close
Set Conn = Nothing
Set Rec = Nothing
Set Stm = Nothing

End Sub

When run, I received "Provider not found" and when I bypass "Conn.Provider" statement I received "Data source name too long". Please advise what is wrong in this subroutine. If all are set, will "Str" contain the value of "doll_per_sdr"?

Windows development | Windows API - Win32
Microsoft 365 and Office | Access | Development
Developer technologies | Visual Basic for Applications
0 comments No comments

1 answer

Sort by: Most helpful
  1. Grailly 1 Reputation point
    2022-01-05T08:14:17.693+00:00

    i think use

    With CreateObject("msxml2.xmlhttp")
    .Open "GET","https://www.bank-maskan.ir/", False

    then using

    Set Ostream=CreateObject("ADODB.Stream")

    Stream object to SaveFile to

    With Ostream
    .Open
    .Type=1
    .Write
    .SaveToFile strPath,2 'OverWrite
    .Close
    End With
    End With

    you try like above may be, i did not try never but saw in google searching

    if helped you plz put here your code to share all

    tnx

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.