if exists

J

Jason

Hi,

Could someone help me to adjust the following code to check if the query
exists, if so then it should not try to create it.

Function CreateSPT(SPTQueryName As String, CmdString As String)

Dim db As dao.Database
Dim qdf As dao.QueryDef

Set db = DBEngine.Workspaces(0).Databases(0)
Set qdf = db.CreateQueryDef(SPTQueryName)

With qdf
.Connect = ConnString(False)
.SQL = CmdString
.Close
End With

End Function
 
B

Brendan Reynolds

Function CreateSPT(SPTQueryName As String, CmdString As String)

Dim db As DAO.Database
Dim qdf As DAO.QueryDef

Set db = DBEngine.Workspaces(0).Databases(0)
For Each qdf In db.QueryDefs
If qdf.Name = SPTQueryName Then
Exit Function
End If
Next qdf

Set qdf = db.CreateQueryDef(SPTQueryName)

With qdf
'.Connect = ConnString(False)
.SQL = CmdString
.Close
End With

End Function
 

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