PC Review


Reply
Thread Tools Rate Thread

how to builit Query by BVA

 
 
Atif
Guest
Posts: n/a
 
      10th Oct 2008
Hi,

How can I creat a Query (Select and Crosstab) using VB code.

Thanks
 
Reply With Quote
 
 
 
 
Alex Dybenko
Guest
Posts: n/a
 
      11th Oct 2008
Hi,
look at CreateQueryDef method in access help

--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com


"Atif" <(E-Mail Removed)> wrote in message
news:99ADB276-E09F-413A-BA1C-(E-Mail Removed)...
> Hi,
>
> How can I creat a Query (Select and Crosstab) using VB code.
>
> Thanks


 
Reply With Quote
 
ollyb303
Guest
Posts: n/a
 
      28th Oct 2008
Here's an example that's working for me:

'Declare variables for SQL query
Dim strSQL As String
Dim strTable As String
Dim strStat As String
Dim strGroup As String
Dim strTransform As String
Dim strPivot As String
Dim strDate As String

'Set variables for SQL query
If StatCombo.Value = "SNBE" Then
strTable = "TPERF_STATS_DAILY_CHT"
Else
strTable = "TPERF_STATS_DAILY_CC"
End If

strStat = StatCombo.Value

strGroup = GroupByCombo.Value

If StatCombo.Value = "CALLS_HANDLED" Then
strTransform = "Sum"
Else
strTransform = "Avg"
End If

strPivot = "NOM_DATE"

strDate = "NOM_DATE"

'Construct SQL query
strSQL = "PARAMETERS [Forms]![SelectDate]![StartDate] DateTime,
[Forms]![SelectDate]![EndDate] DateTime; " & _
"TRANSFORM " & strTransform & "(" & strTable & ".[" & strStat & "]) AS
[" & strTransform & "Of" & strStat & "] " & _
"SELECT " & strTable & ".[" & strGroup & "] " & _
"FROM " & strTable & " " & _
"WHERE (((" & strTable & "." & strDate & ") Between
[Forms]![SelectDate]![StartDate] And [Forms]![SelectDate]![EndDate])) " & _
"GROUP BY " & strTable & ".[" & strGroup & "] " & _
"PIVOT " & strTable & "." & strPivot & "; "

'Pass SQL query to Query1
Dim qdf As DAO.QueryDef

Set qdf = CurrentDb.QueryDefs("Query1")
qdf.SQL = strSQL

Obviously you can create the various strings from which the query is built
however you want.

Hope this helps.

"Alex Dybenko" wrote:

> Hi,
> look at CreateQueryDef method in access help
>
> --
> Best regards,
> ___________
> Alex Dybenko (MVP)
> http://accessblog.net
> http://www.PointLtd.com
>
>
> "Atif" <(E-Mail Removed)> wrote in message
> news:99ADB276-E09F-413A-BA1C-(E-Mail Removed)...
> > Hi,
> >
> > How can I creat a Query (Select and Crosstab) using VB code.
> >
> > Thanks

>

 
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
MS Access metadata repository generation query, matrix generationquery, table-generation query, array-generation query. Roy Roebuck Microsoft Access Database Table Design 1 20th Dec 2008 07:23 PM
Set sub (embedded?) query parameters using VBA, call sub query in primary query with parameters completed Kelii Microsoft Access 4 5th Feb 2007 03:01 AM
verfiy a query like Query Analyzer's parse query function =?Utf-8?B?a2V2aW4=?= Microsoft C# .NET 1 24th Dec 2005 01:33 AM
Sorry for confusion :Re: Can I insert empyt record (blank row) in a query based on condition an asp query Dave Microsoft Frontpage 0 18th Oct 2004 03:42 PM
'Sanity Check' - combine macro, delete query and make table query Mike Webb Microsoft Access Queries 2 17th Feb 2004 02:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:54 AM.