hello,
I've the following function which runs in Access 2010 and returns a variant table. This function runs well
Function dataquery() As Variant()
Dim appExcel As Object
'Excel.Application
Dim lngLastDataRow As Long
Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Dim RS As DAO.Recordset
Dim qry As Variant
Dim aFoo As Variant
Set dbs = CurrentDb
Set appExcel = CreateObject("Excel.Application")
'Set RS = CurrentDb.OpenRecordset("Carnet de commande all fnr", dbOpenSnapshot)
'Set RS = dbs.OpenRecordset("SELECT [Carnet de commande all fnr].Référence FROM [Carnet de commande all fnr];", dbOpenSnapshot)
varFileName = outputfilename
qry = "SELECT [OtifDataToExport].[Mois], " & _
"[OtifDataToExport].[In Advance], " & _
"[OtifDataToExport].[Late], " & _
"[OtifDataToExport].[On time], " & _
"[OtifDataToExport].[Somme] FROM [OtifDataToExport];"
Set RS = dbs.OpenRecordset(qry, dbOpenSnapshot)
With RS
dataquery = .GetRows(.RecordCount)
End With
RS.Close
Set RS = Nothing
Set appExcel = Nothing
End Function
I pass it to excel like via this function:
Function getdata(ByRef databasename As String, bddobjet As Object)
Dim strDBName As String
Dim strMessage As String
Dim appAccess As Object
Dim vartest As String
Dim hd As String
Dim hf As String
Dim recup() As Variant
Set appAccess = bddobjet
hd = Time
'strDBName = "E:\00 - Management\40 - Appro\60 - Tools\30 - Prev\prev.accdb"
strDBName = ThisWorkbook.path & "" & databasename
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
With appAccess
'.OpenCurrentDatabase strDBName
'.Visible = False ' Useful for debugging when true
'.Run "integrationfichierxl", pathOTIFDATA, pathOTIFOUTCOMES
'.Eval ("dataquery()")
End With
recup = appAccess.Eval("dataquery()")
For I = 1 To UBound(appAccess.Eval("dataquery()"), 1)
For J = 1 To UBound(appAccess.Eval("dataquery()"), 2)
K = K + 1
Next J
Next
It seems that I'm unable to copy the variant table as the excel keeps throwing a error, Incompatibility type.
Have you got any clue about this issue?
Thanks.
Arte
I've the following function which runs in Access 2010 and returns a variant table. This function runs well
Function dataquery() As Variant()
Dim appExcel As Object
'Excel.Application
Dim lngLastDataRow As Long
Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Dim RS As DAO.Recordset
Dim qry As Variant
Dim aFoo As Variant
Set dbs = CurrentDb
Set appExcel = CreateObject("Excel.Application")
'Set RS = CurrentDb.OpenRecordset("Carnet de commande all fnr", dbOpenSnapshot)
'Set RS = dbs.OpenRecordset("SELECT [Carnet de commande all fnr].Référence FROM [Carnet de commande all fnr];", dbOpenSnapshot)
varFileName = outputfilename
qry = "SELECT [OtifDataToExport].[Mois], " & _
"[OtifDataToExport].[In Advance], " & _
"[OtifDataToExport].[Late], " & _
"[OtifDataToExport].[On time], " & _
"[OtifDataToExport].[Somme] FROM [OtifDataToExport];"
Set RS = dbs.OpenRecordset(qry, dbOpenSnapshot)
With RS
dataquery = .GetRows(.RecordCount)
End With
RS.Close
Set RS = Nothing
Set appExcel = Nothing
End Function
I pass it to excel like via this function:
Function getdata(ByRef databasename As String, bddobjet As Object)
Dim strDBName As String
Dim strMessage As String
Dim appAccess As Object
Dim vartest As String
Dim hd As String
Dim hf As String
Dim recup() As Variant
Set appAccess = bddobjet
hd = Time
'strDBName = "E:\00 - Management\40 - Appro\60 - Tools\30 - Prev\prev.accdb"
strDBName = ThisWorkbook.path & "" & databasename
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
With appAccess
'.OpenCurrentDatabase strDBName
'.Visible = False ' Useful for debugging when true
'.Run "integrationfichierxl", pathOTIFDATA, pathOTIFOUTCOMES
'.Eval ("dataquery()")
End With
recup = appAccess.Eval("dataquery()")
For I = 1 To UBound(appAccess.Eval("dataquery()"), 1)
For J = 1 To UBound(appAccess.Eval("dataquery()"), 2)
K = K + 1
Next J
Next
It seems that I'm unable to copy the variant table as the excel keeps throwing a error, Incompatibility type.
Have you got any clue about this issue?
Thanks.
Arte