Una famiglia di sistemi di gestione per database relazionali di Microsoft progettati per semplificare l'uso.
Ciao Andrea,
forse il seguente codice puo' esserti utile (devi variare il nome della tabella Table2):
Tieni presente che se come dici la tabella origine ha 500000 records non potrai ottenere una tabella con così tante colonne!!!!
Se l'input al presente codice è una query, allora sostituisci:
Set myRstIn = CurrentDb.OpenRecordset("Select * from Table2")
con
Set myRstIn = CurrentDb.OpenRecordset("NomeQuery")
Option Compare Database
Option Explicit
Function Transpose()
Dim myRstIn As Recordset
Dim myRstOut As Recordset
Dim myTd As TableDef
Dim iR As Double
Dim iC As Double
Dim iFld As Double
Dim Matrice() As String
Set myRstIn = CurrentDb.OpenRecordset("Select * from Table2")
myRstIn.MoveLast
ReDim Matrice(myRstIn.Fields.Count - 1, myRstIn.RecordCount - 1)
myRstIn.MoveFirst
On Error Resume Next
Set myRstOut = CurrentDb.OpenRecordset("Table3")
If Err.Number = 0 Then
DoCmd.SetWarnings False
myRstOut.Close
DoCmd.RunSQL ("Drop Table Table3")
If Err.Number > 0 Then
MsgBox "Tabella non eliminabile!"
Exit Function
End If
DoCmd.SetWarnings True
End If
Err.Clear
Set myTd = CurrentDb.CreateTableDef("Table3")
On Error GoTo 0
For iFld = 0 To myRstIn.RecordCount - 1
myTd.Fields.Append myTd.CreateField("Col" & Format(iFld + 1, "##"), dbText)
Next iFld
For iC = 0 To myRstIn.RecordCount - 1
For iR = 0 To myRstIn.Fields.Count - 1
Matrice(iR, iC) = myRstIn(iR)
Next iR
If iC = 0 Then
CurrentDb.TableDefs.Append myTd
End If
myRstIn.MoveNext
If myRstIn.EOF Then
GoTo Scrivi
End If
Next iC
Scrivi:
Set myRstOut = CurrentDb.OpenRecordset("Table3")
For iR = 0 To myRstIn.Fields.Count - 1
myRstOut.AddNew
For iC = 0 To myRstIn.RecordCount - 1
myRstOut(iC) = Matrice(iR, iC)
Next iC
myRstOut.Update
Next iR
myRstOut.Close
myRstIn.Close
Set myRstOut = Nothing
Set myRstIn = Nothing
End Function
Ciao Mimmo