question about CreateQueryDef

  • Thread starter Daama via AccessMonster.com
  • Start date
D

Daama via AccessMonster.com

I am using CreateQueryDef to create a query named: "User Query".

But it does not show up in my query window and I cannot open by using DoCmd
procedure.

Can anyone help me to make this query shop up as one of the queries in my
database one it is created. The code already works. If run the code a second
time it tells me that the query already exist. So, it is doing the work. The
problem is that I can see my query. I'd appreciate any help..

Daama.


Code:


Private Sub RunQuery()

Dim cn As ADODB.Connection
Dim db As Database
Dim qdf As QueryDef
Dim qdfNew As New QueryDef

Set db = OpenDatabase("faith fund Database")

With db

Set qdf = .CreateQueryDef("User Query", _
"Select * from buyer")

GetRS qdfNew
.QueryDefs.Delete qdfNew.Name
.Close
End With
'DoCmd.OpenQuery ("user Query")
End Sub

Function GetRS(qdf As QueryDef)

Dim RS As ADODB.Recordset


With qdf
Debug.Print .Name
Debug.Print "" & .SQL

Set RS = .OpenRecordset(dbOpenSnapshot)

With RS
.MoveLast
Debug.Print " number of records =" & _
.RecordCount

Debug.Print
.Close
End With

End With
End Function
 
A

Allen Browne

Do you think the line:
.QueryDefs.Delete qdfNew.Name
might have something to do with why it does not show up?

If you don't delete it, this might help:
Application.RefreshDatabaseWindow
 

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