Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 22nd, 2007, 09:42 PM
Registered User
 
Join Date: Jun 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
 
Old January 23rd, 2007, 09:04 PM
Registered User
 
Join Date: Jun 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I got there in the end by doing a work around along the lines of

if qdf.fields.count = 0 then

turn it into a recordset and get the fields from that which worked for some strange reason





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT For Each - Field Names lahatfield XSLT 6 May 15th, 2007 06:33 AM
Query statement has nonexistent field names-FIXED buddyz Classic ASP Databases 3 August 30th, 2006 09:46 AM
Get Field Names fizzerchris Classic ASP Databases 1 February 25th, 2006 05:06 AM
Retrieving Field Names RayRedSox Classic ASP Basics 0 October 12th, 2005 02:16 PM
Retrieving Dynamic Field Names tdaustin Classic ASP Basics 4 January 12th, 2004 11:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.