Connecting Tech Pros Worldwide Help | Site Map

Open and save query with code

  #1  
Old November 13th, 2006, 04:05 PM
eighthman11
Guest
 
Posts: n/a
Hello everyone. I have a table linked to an excel spreadsheet. I have
an append query based on this link table. I receive an error when I
run the append query "numeric field overflow". I have noticed that
when I open then save the append query and then run it I get no error.
I am assuming that the error is being caused by Access Optimizing. The
easy solution to my problem is if it is possible to run some VB code
that will save my append query before I run my append query.

Is there a way With code to open and save a query? Thanks

  #2  
Old November 14th, 2006, 04:05 AM
Kelii
Guest
 
Posts: n/a

re: Open and save query with code



eighthman11,

If I'm interpreting your question correctly, yes there is an easy way
to create and save a query with code.

Public Sub CreateQuery (strName as String, strSQL as String)
Dim dbs as Database
Dim qdf as Querydef

Set dbs = CurrentDb
Set qdf = dbs.CreateQueryDef(strName, strSQL)

Set qdf = Nothing
Set dbs = Nothing

End Sub

Of course for this to work you need to be able to write a SQL statement
that fits your needs. As a side note, the above is accomplished through
DAO, most advanced developers use ADO as their preferred alternative.
However, if you are working solely through Access/VBA, then DAO is
quite sufficient.

Kelii

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Code Simon answers 2 August 12th, 2006 06:45 PM
Creating forn controls with code John T Ingato answers 1 July 23rd, 2006 05:55 PM
Help with code Mark answers 6 November 13th, 2005 05:00 AM
Macro to save query as Excel file Carl answers 5 November 12th, 2005 03:45 PM