Connecting Tech Pros Worldwide Forums | Help | Site Map

Open and save query with code

eighthman11
Guest
 
Posts: n/a
#1: Nov 13 '06
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


Kelii
Guest
 
Posts: n/a
#2: Nov 14 '06

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 Microsoft Access / VBA bytes