if exist?

J

Jason

Hi,

I have this function where i create temporary pass-through-queries.
However, once the query is created the function fails if i try to use it
again.

Can someone help me adjust the code so it will check if the query exists.

Function CreateSPT(SPTQueryName As String, SQLString As String)

Dim mydatabase As DAO.Database
Dim myquerydef As DAO.QueryDef

Set mydatabase = DBEngine.Workspaces(0).Databases(0)
Set myquerydef = mydatabase.CreateQueryDef(SPTQueryName)


myquerydef.Connect = GetODBCConnection
myquerydef.SQL = SQLString
myquerydef.Close
End Function
 
B

Bas Cost Budde

Function CreateSPT(SPTQueryName As String, SQLString As String)
on error resume next
Dim mydatabase As DAO.Database
Dim myquerydef As DAO.QueryDef

Set mydatabase = DBEngine.Workspaces(0).Databases(0)
Set myquerydef = mydatabase.CreateQueryDef(SPTQueryName)
if err=(the error number that occurs) then
set myquerydef=mydatabase.querydefs(sptqueryname)
else
'something that exits the routine, or handles error
endif
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top