Displaying records from a temporary querydef

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi Guys,

I needs some help is displaying the records from a createquerydef similar to
the QBE grid. What is the best way to display the all of the records?? The
code that I have used opens a temporary query using the createquerydef
function using a select query ( ie. createquerydef("", select * from table X)
). The returned records I don't know how to display them similar to the nice
QBE grid.

Is there a way to do this??

Please help me??

Cheers,
Ian
 
Ian,

Make sure the querydef you create can create an output to a query.

So the qeurydef could look something like this:

Dim sSQL as string

sSQL= "SELECT * FROM tableX"

currentdb.querydefs("query1").SQL=sSQL

So make sure you have a query called query1. After the code is executed
query1 will represent your "Select * from tablex".

hth
 
Thanks for your reply maurice,

Will this allow me to activate this code more than once, cause I tried using
a createquerydef("Joeblow", Select from *...) and when I came to run the
query again I got an error saying the query was already in the database, and
I didn't know how to delete the query via VBA code. I know how to delete a
table using the DEROP table vb, will your code work in subsequent selections
of the query??
 
Yes, this will allow you to activate the code more than once. The querydef
will be refilled everytime you run the code. You don't have to delete
anything...
 
Thanks Maurice,

It works well!!

I noticed that I had to have the createquerydef first and then utilise the
code that you gave to me!!

Is there any way that I can sense if the query firstly exists and if it does
exist just run your code?? I was thinking of using a if statement that
would be able to set up the query first time the query is run (using the
createquerydef and then the else statement would utilise the code that you
provided to me??

Cheers in advance!!
 
Yes you could, create the query and then use the querydef code to use the
newly created query.

hth
 
Ian, the below first IF will delete a query if it exists. The second IF will
create a dummy query if none exists.
The query tested for, or created is "qtempQuery"
HTH UpRider

Dim qthisQuery as DAO.QueryDef
If DCount("Name", "MSysObjects", "[Name] = 'qtempQuery'") = 1 Then
DoCmd.DeleteObject acQuery, "qtempQuery"
End If

If DCount("Name", "MSysObjects", "[Name] = 'qtempQuery'") = 0 Then
Set qthisQuery = CurrentDb.CreateQueryDef("qtempQuery", "")
End If
 
Uprider this is exactly what I was after, this is superb stuff!!

This has helped me heeps,,

Many thanks to you Uprider and maurice!!

Cheers,

ian

UpRider said:
Ian, the below first IF will delete a query if it exists. The second IF will
create a dummy query if none exists.
The query tested for, or created is "qtempQuery"
HTH UpRider

Dim qthisQuery as DAO.QueryDef
If DCount("Name", "MSysObjects", "[Name] = 'qtempQuery'") = 1 Then
DoCmd.DeleteObject acQuery, "qtempQuery"
End If

If DCount("Name", "MSysObjects", "[Name] = 'qtempQuery'") = 0 Then
Set qthisQuery = CurrentDb.CreateQueryDef("qtempQuery", "")
End If

Ian Shaw said:
Thanks Maurice,

It works well!!

I noticed that I had to have the createquerydef first and then utilise the
code that you gave to me!!

Is there any way that I can sense if the query firstly exists and if it
does
exist just run your code?? I was thinking of using a if statement that
would be able to set up the query first time the query is run (using the
createquerydef and then the else statement would utilise the code that you
provided to me??

Cheers in advance!!
 
Hi Guys,

At work and on one of the guys on the network the code fails to operate, the
error says that the:
You do not have the necessary permisions to use the "MSYStables" object.

The code halsts at the
qdf.SQL = strsql

What is the provblem here??

And yet on my machine the code works fine!!
I logged a guy onto my machine and still had the error. I tried more than
one guy and still had the error.

Please help me!!


Cheers,
 
Back
Top