Error getting field names from query
Hi I have the following function designed to make a temp table out of a select query, it works for all queries except on one I get the error message:
3264 "no field defined--cannot append tabledef"
The reason for this is when it gets to the "For Each fld In qdf.Fields" part it cannot see any fields in the query so doesn't appned any.
I have tried
* compact and repair
* decompile
* recreating the query
* jetcomp
* for i = 0 to qdf.Fields.Count - 1
Any ideas,
The function…...
Public Sub CreateTempTableQuery(QueryName As String, TempTableName As String)
Dim tdf As DAO.TableDef
Dim qdf As DAO.QueryDef
Dim fld As DAO.Field
Set tdf = DBEngine(0)(0).CreateTableDef(TempTableName)
Set qdf = DBEngine(0)(0).QueryDefs(QueryName)
For Each fld In qdf.Fields
tdf.Fields.Append tdf.CreateField(fld.Name, fld.Type)
Next fld
DBEngine(0)(0).TableDefs.Append tdf
End Sub
Hi I have the following function designed to make a temp table out of a select query, it works for all queries except on one I get the error message:
3264 "no field defined--cannot append tabledef"
The reason for this is when it gets to the "For Each fld In qdf.Fields" part it cannot see any fields in the query so doesn't appned any.
I have tried
* compact and repair
* decompile
* recreating the query
* jetcomp
* for i = 0 to qdf.Fields.Count - 1
Any ideas,
The function…...
Public Sub CreateTempTableQuery(QueryName As String, TempTableName As String)
Dim tdf As DAO.TableDef
Dim qdf As DAO.QueryDef
Dim fld As DAO.Field
Set tdf = DBEngine(0)(0).CreateTableDef(TempTableName)
Set qdf = DBEngine(0)(0).QueryDefs(QueryName)
For Each fld In qdf.Fields
tdf.Fields.Append tdf.CreateField(fld.Name, fld.Type)
Next fld
DBEngine(0)(0).TableDefs.Append tdf
End Sub
Last edited: