11. december 2003 - 12:16Der er
8 kommentarer og 1 løsning
Save recordset til tabel
Hejsa!
Jeg henter noget data fra et excelsheet over i et recordset for at kontrollere de enkelte rækker inden de importeres til min tabel.
I øjeblikket kontrollere jeg data'en ved at løbe igennem recordset med move.next, når alle rækker så er blevet godkendt importere jeg så hele excelsheetet vha. DoCmd.Transferspreadsheet, og det virker sådan set fint nok. Meeen...
Det jeg godt kunne tænke mig i stedet, var at kunne importere/copiere rækkerne fra recordsetet enkeltvis over i min tabel, når jeg løber dem igennem og har godkendt den enkelte række.
Er der nogen der forstå hvor jeg vil hen og kan hjælpe mig.
I made it work using 'AddNew', but is it REALLY anoying that I have to specify each field I want to add (e.g. rsTable!RawMaterialName = rsExcel.Fields(0), rs.Table!RawMaterialType = rsExcel.Fields(1)... etc.) Isn't it possible to make some kind loop to handle this?
strSQL = "SELECT * FROM [Chemical Analysis]" Set rsTable = CurrentDb.OpenRecordset(strSQL)
While Not rsExcel.EOF rsTable.AddNew For j = 0 To rsExcel.Fields.Count - 1 rsTable!Fields(j) = rsExcel.Fields(j) Next j rsTable.Update rsExcel.MoveNext Wend
I understand that you wnat the import routine to be as flexible as possible, but as far as I see it you have a destination table which you know the layout of so you must obviously need to know that layout of the data you are importing. So I cant see wht you cant use the soultion i gave here 11/12-2003 16:54:29 or am I missing something?
I'm pretty sure that your solution works just fine, I was just looking for a way to avoid having to write every single 'Field' and corresponding 'Value' illustrated below. Currently, each row in Excel has 41 Values that have to be exported into the table and I was hopind this could be done using some kind of loop...
Btw, the data is imported from an excel template that I constructed, which means that I know the exact layout of both data origin and destination. Is that sufficient to make an import loop, or is it simply not possible to make such a loop...
Yes it is possible, but the work involved doesnt make it worth while! The loop would have also need to find the data type of each field as the format of the values list is different for numbers and text.
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.