There is a task to get some rows from the postgresql database, from VBA. I make a request with my hands and I know for sure that there are ~ 200 rows in the table. But if I make it a VBA script, then UBound says that I have only 10 lines in the record and trying to access line 11 causes an out of range error. I am sure that there are more than 10 lines and there are more than 10 in LIMIT, but there are always 10 lines. Yes, I can do it with OFFSET, but I want to reduce the number of queries.
Sub main()
Dim query As String
'Create Connection
Set conn = CreateObject("ADODB.Connection")
strCnx = "Driver={PostgreSQL Unicode};Server=10.84._._;Port=5432;Database=_;UID=_;PWD=_;"
conn.Open strCnx
'Query the Database
Set rs = CreateObject("ADODB.recordset")
rs.Open "SELECT id, FROM dbo.orders ORDER BY tid DESC LIMIT 100", conn
Record = rs.GetRows()
Worksheets("index").Columns("A").ClearContents
Cells(1, 1) = Record(0, 10)
rs.Close
CodePudding user response:
rs.CursorLocation = adUseClient