PC Review


Reply
Thread Tools Rate Thread

opening query from VBA

 
 
Wim
Guest
Posts: n/a
 
      1st Feb 2004
Hi all,

I want to create a temporary querydef, open it, inspect
the contents and then close it.

Creating it works fine :
Set qdf = db.CreateQueryDef("", strSQL)

But then how do I open it and read it ?

Thanks in advance,

Wim

 
Reply With Quote
 
 
 
 
John Vinson
Guest
Posts: n/a
 
      1st Feb 2004
On Sat, 31 Jan 2004 21:38:51 -0800, "Wim"
<(E-Mail Removed)> wrote:

>Hi all,
>
>I want to create a temporary querydef, open it, inspect
>the contents and then close it.
>
>Creating it works fine :
>Set qdf = db.CreateQueryDef("", strSQL)
>
>But then how do I open it and read it ?
>
>Thanks in advance,
>
>Wim

Open a Recordset based on the querydef:

Dim rs As DAO.Recordset
Set rs = qdf.OpenRecordset
rs.MoveFirst
Do Until rs.EOF
thisvar = rs!fieldname
thatvar = rs!anotherfield
rs.MoveNext
Loop

John W. Vinson[MVP]
Come for live chats every Tuesday and Thursday
http://go.compuserve.com/msdevapps?loc=us&access=public
 
Reply With Quote
 
Wim
Guest
Posts: n/a
 
      1st Feb 2004
Hi John,

Thanks for your answer. I'm afraid I didn't explain my
problem well enough. As a matter of fact I want to have a
table-like browser, based on the on-the-fly query, so that
I can verify very quickly if all my records are valid.

Could you suggest a snippet of code for that ?

Thank you,

Wim



>-----Original Message-----
>On Sat, 31 Jan 2004 21:38:51 -0800, "Wim"
><(E-Mail Removed)> wrote:
>
>>Hi all,
>>
>>I want to create a temporary querydef, open it, inspect
>>the contents and then close it.
>>
>>Creating it works fine :
>>Set qdf = db.CreateQueryDef("", strSQL)
>>
>>But then how do I open it and read it ?
>>
>>Thanks in advance,
>>
>>Wim

>Open a Recordset based on the querydef:
>
>Dim rs As DAO.Recordset
>Set rs = qdf.OpenRecordset
>rs.MoveFirst
>Do Until rs.EOF
>thisvar = rs!fieldname
>thatvar = rs!anotherfield
>rs.MoveNext
>Loop
>
> John W. Vinson[MVP]
> Come for live chats every Tuesday and Thursday
>http://go.compuserve.com/msdevapps?loc=us&access=public
>.
>

 
Reply With Quote
 
Flupke
Guest
Posts: n/a
 
      1st Feb 2004
Hi Wim,

These are the steps I would take:

1. Create a form and set ALL the fields you ever want to
view on that form.
2. Use code to change your query as you did in your code.
Make sure the SQL is correct of course!
3. Using code :
- change the visible property of each field you wish to
view (or not to view)
- change the recordsource of the form by using the
following code snippet:
frm.Recordsource = qdf.Name if the qry is the query you
just altered!


Good luck!

>-----Original Message-----
>Hi John,
>
>Thanks for your answer. I'm afraid I didn't explain my
>problem well enough. As a matter of fact I want to have

a
>table-like browser, based on the on-the-fly query, so

that
>I can verify very quickly if all my records are valid.
>
>Could you suggest a snippet of code for that ?
>
>Thank you,
>
>Wim
>
>
>
>>-----Original Message-----
>>On Sat, 31 Jan 2004 21:38:51 -0800, "Wim"
>><(E-Mail Removed)> wrote:
>>
>>>Hi all,
>>>
>>>I want to create a temporary querydef, open it, inspect
>>>the contents and then close it.
>>>
>>>Creating it works fine :
>>>Set qdf = db.CreateQueryDef("", strSQL)
>>>
>>>But then how do I open it and read it ?
>>>
>>>Thanks in advance,
>>>
>>>Wim

>>Open a Recordset based on the querydef:
>>
>>Dim rs As DAO.Recordset
>>Set rs = qdf.OpenRecordset
>>rs.MoveFirst
>>Do Until rs.EOF
>>thisvar = rs!fieldname
>>thatvar = rs!anotherfield
>>rs.MoveNext
>>Loop
>>
>> John W. Vinson[MVP]
>> Come for live chats every Tuesday and Thursday
>>http://go.compuserve.com/msdevapps?loc=us&access=public
>>.
>>

>.
>

 
Reply With Quote
 
Guest
Posts: n/a
 
      1st Feb 2004
Hi Flupke,

Thanks for your help.
I'll give it a try.

Kwik
>-----Original Message-----
>Hi Wim,
>
>These are the steps I would take:
>
>1. Create a form and set ALL the fields you ever want to
>view on that form.
>2. Use code to change your query as you did in your code.
>Make sure the SQL is correct of course!
>3. Using code :
>- change the visible property of each field you wish to
>view (or not to view)
>- change the recordsource of the form by using the
>following code snippet:
>frm.Recordsource = qdf.Name if the qry is the query you
>just altered!
>
>
>Good luck!
>
>>-----Original Message-----
>>Hi John,
>>
>>Thanks for your answer. I'm afraid I didn't explain my
>>problem well enough. As a matter of fact I want to have

>a
>>table-like browser, based on the on-the-fly query, so

>that
>>I can verify very quickly if all my records are valid.
>>
>>Could you suggest a snippet of code for that ?
>>
>>Thank you,
>>
>>Wim
>>
>>
>>
>>>-----Original Message-----
>>>On Sat, 31 Jan 2004 21:38:51 -0800, "Wim"
>>><(E-Mail Removed)> wrote:
>>>
>>>>Hi all,
>>>>
>>>>I want to create a temporary querydef, open it,

inspect
>>>>the contents and then close it.
>>>>
>>>>Creating it works fine :
>>>>Set qdf = db.CreateQueryDef("", strSQL)
>>>>
>>>>But then how do I open it and read it ?
>>>>
>>>>Thanks in advance,
>>>>
>>>>Wim
>>>Open a Recordset based on the querydef:
>>>
>>>Dim rs As DAO.Recordset
>>>Set rs = qdf.OpenRecordset
>>>rs.MoveFirst
>>>Do Until rs.EOF
>>>thisvar = rs!fieldname
>>>thatvar = rs!anotherfield
>>>rs.MoveNext
>>>Loop
>>>
>>> John W. Vinson[MVP]
>>> Come for live chats every Tuesday and Thursday
>>>http://go.compuserve.com/msdevapps?loc=us&access=public
>>>.
>>>

>>.
>>

>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Query Confirmations still opening tighe Microsoft Access Database Table Design 2 3rd Feb 2010 06:35 PM
Error message opening query when opening file. Leo Rod Microsoft Excel Discussion 0 18th Mar 2008 03:24 PM
Opening a form via a query =?Utf-8?B?TWVsemE=?= Microsoft Access Queries 6 29th May 2007 06:38 AM
opening query from listbox =?Utf-8?B?Sm9obkU=?= Microsoft Access Form Coding 1 24th Apr 2006 01:14 AM
opening a form when a query is run =?Utf-8?B?U2FuZA==?= Microsoft Access Queries 1 5th Feb 2004 07:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:42 PM.