set column widths after doing a CreateQueryDef and a doCmd.OpenQuery

F

Ferd Berfel

that's about it... I want to create a query on the fly, e.g.
sqlStr = "select first,last,other,whatever from myTable"
then do a

Set qdf = db.CreateQueryDef("ShowTheData", sqlStr )
DoCmd.OpenQuery "ShowTheData", acViewNormal, acEdit


and then
set column 1 to (e.g) 50
column 2 to 100
column 3 to ....


is this possible?

tia!
f
 
D

Dirk Goldgar

Ferd Berfel said:
that's about it... I want to create a query on the fly, e.g.
sqlStr = "select first,last,other,whatever from myTable"
then do a

Set qdf = db.CreateQueryDef("ShowTheData", sqlStr )
DoCmd.OpenQuery "ShowTheData", acViewNormal, acEdit


and then
set column 1 to (e.g) 50
column 2 to 100
column 3 to ....


is this possible?

You can probably do something like this:

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

Set db = CurrentDb
Set qdf = db.CreateQueryDef("ShowTheData", "SELECT * FROM Table1")
Set qdf = Nothing
Set db = Nothing

DoCmd.OpenQuery "ShowTheData"

With Screen.ActiveDatasheet.Controls
.Item(0).ColumnWidth = 1440 ' 1 inch
.Item(1).ColumnWidth = 2880 ' 2 inches
.Item(2).ColumnWidth = 4320 ' 3 inches
End With

Note that the query now created will remain in the database until you
delete it.
 
F

Ferd Berfel

one more question....

is there a way to avoid the "Do you want to save changes to the layout
of query 'xyz'? " message?

for example, a way to force a save (even though it will be deleted
upon next run)

or another trick?


thanks again,
f
 
D

Dirk Goldgar

Ferd Berfel said:
one more question....

is there a way to avoid the "Do you want to save changes to the layout
of query 'xyz'? " message?

for example, a way to force a save (even though it will be deleted
upon next run)

or another trick?

After opening the query and resizing the columns, execute the statement

DoCmd.Save acQuery, "ShowTheData"

That ought to do it.
 
F

Ferd Berfel

oops, a little plunking around and I got it... thanks again...

doCmd.Save

does the trick when trying to avoid the "do you want to save the layout" messages.

Thanx again!

f
 
C

chiddo

I just wanted to add a note that you might want to automaticly delet
the query when done with:

docmd.DeleteObject acQuery

-Lun
 
Top