PC Review


Reply
Thread Tools Rate Thread

Creating a query with a module

 
 
Liz C
Guest
Posts: n/a
 
      24th Feb 2009
I have created pass-through queries using a function before, but was
wondering how I would go about creating a function/module to create a regular
select query.

Below is the sql view of the query I want it to create:

SELECT VolumeVAS1Q.meter_number, VolumeVAS1Q.MaxOfacct_period_cym AS
acct_period_cym, VolumeVAS1Q.prod_date_time, VolumeVAS1Q.alloc_dth,
VolumeMeas1Q.btu_factor, VolumeMeas1Q.meter_mcf
FROM VolumeMeas1Q INNER JOIN VolumeVAS1Q ON (VolumeMeas1Q.prod_date_time =
VolumeVAS1Q.prod_date_time) AND (VolumeMeas1Q.meter_number =
VolumeVAS1Q.meter_number)
ORDER BY VolumeVAS1Q.meter_number;

Can someone please help me out?

Thank you in advance!

Liz
 
Reply With Quote
 
 
 
 
Piet Linden
Guest
Posts: n/a
 
      24th Feb 2009
This worked... not pretty, but fairly simple...

Public Function CreateQuery(strQueryName)

CreateQuery = False
Dim qdf As DAO.querydef

Set qdf = DBEngine(0)(0).CreateQueryDef(strQueryName, fSQL)

CurrentDb.QueryDefs.Refresh

CreateQuery = True
End Function

Public Function fSQL() As String
fSQL = "SELECT VolumeVAS1Q.meter_number,
VolumeVAS1Q.MaxOfacct_period_cym AS "
fSQL = fSQL & "acct_period_cym, VolumeVAS1Q.prod_date_time,
VolumeVAS1Q.alloc_dth, "
fSQL = fSQL & "VolumeMeas1Q.btu_factor, VolumeMeas1Q.meter_mcf "
fSQL = fSQL & "FROM VolumeMeas1Q INNER JOIN VolumeVAS1Q ON
(VolumeMeas1Q.prod_date_time = "
fSQL = fSQL & "VolumeVAS1Q.prod_date_time) AND
(VolumeMeas1Q.meter_number = "
fSQL = fSQL & "VolumeVAS1Q.meter_number) "
fSQL = fSQL & "ORDER BY VolumeVAS1Q.meter_number;"
End Function
 
Reply With Quote
 
Liz C
Guest
Posts: n/a
 
      24th Feb 2009
Where would I put the name I want for the query (VolumeQ)?

Thanks Piet!

"Piet Linden" wrote:

> This worked... not pretty, but fairly simple...
>
> Public Function CreateQuery(strQueryName)
>
> CreateQuery = False
> Dim qdf As DAO.querydef
>
> Set qdf = DBEngine(0)(0).CreateQueryDef(strQueryName, fSQL)
>
> CurrentDb.QueryDefs.Refresh
>
> CreateQuery = True
> End Function
>
> Public Function fSQL() As String
> fSQL = "SELECT VolumeVAS1Q.meter_number,
> VolumeVAS1Q.MaxOfacct_period_cym AS "
> fSQL = fSQL & "acct_period_cym, VolumeVAS1Q.prod_date_time,
> VolumeVAS1Q.alloc_dth, "
> fSQL = fSQL & "VolumeMeas1Q.btu_factor, VolumeMeas1Q.meter_mcf "
> fSQL = fSQL & "FROM VolumeMeas1Q INNER JOIN VolumeVAS1Q ON
> (VolumeMeas1Q.prod_date_time = "
> fSQL = fSQL & "VolumeVAS1Q.prod_date_time) AND
> (VolumeMeas1Q.meter_number = "
> fSQL = fSQL & "VolumeVAS1Q.meter_number) "
> fSQL = fSQL & "ORDER BY VolumeVAS1Q.meter_number;"
> End Function
>

 
Reply With Quote
 
Piet Linden
Guest
Posts: n/a
 
      25th Feb 2009
?CreateQuery("MyQuery")

or if you use just plain DAO (if you can), it would be

Set qdf = DBEngine(0)(0).CreateQueryDef("MyQuery", "SELECT ...")
 
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
Creating UDF by Class Module (Leo)? Leo Microsoft Excel Misc 1 2nd Dec 2008 10:59 AM
Creating a plug-in module sony.m.2007@googlemail.com Microsoft ASP .NET 3 9th Jun 2008 02:44 PM
Creating a module =?Utf-8?B?TmluaWVs?= Microsoft Access VBA Modules 2 8th Nov 2006 05:08 PM
creating a new module and populating in with vba geskerrett@hotmail.com Microsoft Access 0 28th Sep 2006 09:58 PM
IIF's Text is Too Long in Query -- Need help w/ creating a module Tom Microsoft Access Queries 4 12th Sep 2004 01:31 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:29 AM.