Full Version: Code Needed! If Query "newabfrage" Exists Then Delete It, If Not Then Create A Query "abfragenew"
UtterAccess Discussion Forums > Microsoft® Access > Access Queries
dirk_zahn
Hi Guys,

I need so Code
There's the description

check out If Query "AbfrageNew" exists then delete it, if not then create a Query "AbfrageNew"

Thanks!
Zahn
Peter46
There should be no need to delete and create.

You can modify the sql of a query...

currentdb.querydefs("AbfrageNew").Sql = " your sql here"
dirk_zahn
Hi Peter,

You mean with .SQL, the Query will rewrite?
dirk_zahn
Hi Peter,

I wrote something like this:

Dim sqlstr As String 'the String to save my SQL

CurrentDb.QueryDefs("AbfrageNew").sql = "sqlstr"

the error said following:

Invaild SQL statement: expected "Delete" "Selet" "Insert"...something like that.

What should I do?

Thanks
Zahn
Alan_G
Hi

You need to create the SQL of the query and set the string variable you've declared (sqlstr) to it, something like this

CODE
Dim strSQL As String
Dim qdf As DAO.QueryDef

strSQL = "SELECT Field1, Field2, Field3 FROM SomeTable"
Set qdf = CurrentDb.QueryDefs("AbfrageNew")
qdf.SQL = strSQL

Set qdf = Nothing


Change the SQL statement to your actual SQL
theDBguy
Hi Zahn,

If the query did not exist, how were you planning to create it? What is it for? What is it supposed to do?

Just my 2 cents... 2cents.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.