INSERT array into table ETA

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

INSERT array into table ETA

Post by sal21 »

Code: Select all

...
For R = 1 To 2
        
            For X = 1 To 16
                VALORE = ElementHtml(T).rows(R).cells(X).innerText
                ReDim Preserve ARRAYOP(X)
                ARRAYOP(X) = VALORE
            Next X
            
                For I = 1 To UBound(ARRAYOP)
                Debug.Print ARRAYOP(I)
                Next I
            
            Erase ARRAYOP
            
        Next R        
        ...
i fill an array with this code

now after the first for next with X, i need to append into table ETA the value of array

example:
first item of array in filed 00-04, second item of array in filed 05-09... last item in in fiel >>74
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78237
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: INSERT array into table ETA

Post by HansV »

Why use an array? I'd write the values directly.
Open an ADODB recordset RST on the table ETA.

Code: Select all

        For R = 1 To 2
            RST.AddNew
            For X = 1 To 16
                VALORE = ElementHtml(T).Rows(R).Cells(X).innerText
                RST.Fields(Format(X - 1, "00") & "-" & Format(X + 3, "00")) = VALORE
            Next X
            RST.Update
        Next R
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: INSERT array into table ETA

Post by sal21 »

HansV wrote:
04 Dec 2022, 19:16
Why use an array? I'd write the values directly.
Open an ADODB recordset RST on the table ETA.

Code: Select all

        For R = 1 To 2
            RST.AddNew
            For X = 1 To 16
                VALORE = ElementHtml(T).Rows(R).Cells(X).innerText
                RST.Fields(Format(X - 1, "00") & "-" & Format(X + 3, "00")) = VALORE
            Next X
            RST.Update
        Next R
array only for experiment...

in othe case for each fon next X, i need to insert in field ISTAT the value of MYISTAT

and...OPS

HAVE error on the second element of the for next X

is this correct

Code: Select all

...
 For R = 1 To 2
            RS.AddNew
            For X = 1 To 16
                VALORE = ElementHtml(T).rows(R).cells(X).innerText
                RS.Fields(Format(X - 1, "00") & "-" & Format(X + 3, "00")) = VALORE
            Next X
            RS.Update
        Next R
        ...
You do not have the required permissions to view the files attached to this post.
Last edited by sal21 on 04 Dec 2022, 19:58, edited 2 times in total.

User avatar
HansV
Administrator
Posts: 78237
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: INSERT array into table ETA

Post by HansV »

You can set the value of ISTAT just above RST.Update
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: INSERT array into table ETA

Post by sal21 »

HansV wrote:
04 Dec 2022, 19:55
You can set the value of ISTAT just above RST.Update
replyed before you post...

User avatar
HansV
Administrator
Posts: 78237
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: INSERT array into table ETA

Post by HansV »

I cannot help you with that, sorry.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: INSERT array into table ETA

Post by sal21 »

HansV wrote:
04 Dec 2022, 20:09
I cannot help you with that, sorry.
HOW about...

my study,

Code: Select all

...
For R = 1 To 2
                RS.AddNew
                RS.Fields("ISTAT").Value = ISTAT
                For X = 1 To 16
                    VALORE = ElementHtml(T).rows(R).cells(X).innerText
                    RSNAME = RS.Fields(X).Name
                    RS.Fields(RSNAME).Value = VALORE
                Next X
                RS.Update
            Next R
            ....
Last edited by sal21 on 04 Dec 2022, 20:40, edited 1 time in total.

User avatar
HansV
Administrator
Posts: 78237
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: INSERT array into table ETA

Post by HansV »

That looks OK.
Best wishes,
Hans