#1   Report Post  
Posted to microsoft.public.excel.misc
Sam Sam is offline
external usenet poster
 
Posts: 699
Default query a recordset

Hi

How do i query an open recordset. currently i have a query and then i have
another query that queries it.

i will post the query and the recordset SQL

thanks,

sam


this is the query:

Code:
SELECT DISTINCT PPYearlyIndex.PgpPayGroup, PPYearlyIndex.PgpPeriodStartDate,
PPYearlyIndex.PgpPeriodEndDate
FROM PPYearlyIndex
WHERE (((PPYearlyIndex.PayperiodIndex) Between
[Forms]![RetentionAllFrm]![cboPayperiodIndexStart] And
[Forms]![RetentionAllFrm]![cboPayperiodIndexEnd]) AND
((PPYearlyIndex.PayperiodYear) Between
[Forms]![RetentionAllFrm]![cboPayperiodYearStart] And
[Forms]![RetentionAllFrm]![cboPayperiodYearEnd]));



now i have this recordset in my VBA:


Code:
strSQL = "SELECT PPAllFctsRetentionQry.PgpPayGroup,
Min(PPAllFctsRetentionQry.PgpPeriodStartDate) AS FirstStartDate,
Max(PPAllFctsRetentionQry.PgpPeriodStartDate) AS LastStartDate,
Min(PPAllFctsRetentionQry.PgpPeriodEndDate) AS FirstEndDate,
Max(PPAllFctsRetentionQry.PgpPeriodEndDate) AS LastEndDate " & _
" FROM PPAllFctsRetentionQry GROUP BY
PPAllFctsRetentionQry.PgpPayGroup;"
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,101
Default query a recordset

This is what I use

Private Sub QueryAccessDB()
Dim cnn As ADODB.Connection
Dim rs1 As ADODB.Recordset
Dim strSQL1 As String, strConn
Dim i As Integer
Dim mydate1 As String
Dim mydate2 As String
mydate1 = Sheets(1).Range("F1")
mydate2 = Sheets(1).Range("F2")
i = 1

'Use for Access (jet)
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=C:\Ilsa\Data\" _
& "Ilsa.mdb;Persist Security Info=False"

'Use for jet
strSQL1 = "SELECT FIELDNAME, FIELDNAME2 " _
& "FROM TABLENAME " _
& "WHERE (((TIME_STAMP) Between #" & mydate1 & "# " _
& "And #" & mydate2 & "#)) " _
& "ORDER BY FIELDNAME; "

Set cnn = New ADODB.Connection
Set rs1 = New ADODB.Recordset
cnn.Open strConn
rs1.Open strSQL1, cnn, adOpenForwardOnly, adLockReadOnly
Do While rs1.EOF = False
Sheets("Sheet1").Range("A" & i) = rs1!FIELDNAME1
'Sheets("Sheet1").Range("B" & i) = rs1!FIELDNAME2
'Sheets("Sheet1").Range("C" & i) = rs1!FIELDNAME3
'Sheets("Sheet1").Range("D" & i) = rs1!FIELDNAME4
'Sheets("Sheet1").Range("E" & i) = rs1!FIELDNAME5
'Sheets("Sheet1").Range("F" & i) = rs1!FIELDNAME6
'Sheets("Sheet1").Range("G" & i) = rs1!FIELDNAME7
'Sheets("Sheet1").Range("H" & i) = rs1!FIELDNAME8
i = i + 1
rs1.MoveNext
Loop
rs1.Close
cnn.Close
End Sub

"SAm" wrote:

Hi

How do i query an open recordset. currently i have a query and then i have
another query that queries it.

i will post the query and the recordset SQL

thanks,

sam


this is the query:

Code:
SELECT DISTINCT PPYearlyIndex.PgpPayGroup, PPYearlyIndex.PgpPeriodStartDate,
PPYearlyIndex.PgpPeriodEndDate
FROM PPYearlyIndex
WHERE (((PPYearlyIndex.PayperiodIndex) Between
[Forms]![RetentionAllFrm]![cboPayperiodIndexStart] And
[Forms]![RetentionAllFrm]![cboPayperiodIndexEnd]) AND
((PPYearlyIndex.PayperiodYear) Between
[Forms]![RetentionAllFrm]![cboPayperiodYearStart] And
[Forms]![RetentionAllFrm]![cboPayperiodYearEnd]));



now i have this recordset in my VBA:


Code:
strSQL = "SELECT PPAllFctsRetentionQry.PgpPayGroup,
Min(PPAllFctsRetentionQry.PgpPeriodStartDate) AS FirstStartDate,
Max(PPAllFctsRetentionQry.PgpPeriodStartDate) AS LastStartDate,
Min(PPAllFctsRetentionQry.PgpPeriodEndDate) AS FirstEndDate,
Max(PPAllFctsRetentionQry.PgpPeriodEndDate) AS LastEndDate " & _
" FROM PPAllFctsRetentionQry GROUP BY
PPAllFctsRetentionQry.PgpPayGroup;"

  #3   Report Post  
Posted to microsoft.public.excel.misc
Sam Sam is offline
external usenet poster
 
Posts: 699
Default query a recordset

first of all i would like to appologize for not posting this in the correct
category. this is an access question not an excel question (even though it
doesn't make much of a difference).

second, what you are posting is code to move through a recordset, and this
is not what i need. what i am looking for is to "query" a recordset.

thanks for your reply, but please help me find a solution.

sam

"Mike" wrote:

This is what I use

Private Sub QueryAccessDB()
Dim cnn As ADODB.Connection
Dim rs1 As ADODB.Recordset
Dim strSQL1 As String, strConn
Dim i As Integer
Dim mydate1 As String
Dim mydate2 As String
mydate1 = Sheets(1).Range("F1")
mydate2 = Sheets(1).Range("F2")
i = 1

'Use for Access (jet)
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=C:\Ilsa\Data\" _
& "Ilsa.mdb;Persist Security Info=False"

'Use for jet
strSQL1 = "SELECT FIELDNAME, FIELDNAME2 " _
& "FROM TABLENAME " _
& "WHERE (((TIME_STAMP) Between #" & mydate1 & "# " _
& "And #" & mydate2 & "#)) " _
& "ORDER BY FIELDNAME; "

Set cnn = New ADODB.Connection
Set rs1 = New ADODB.Recordset
cnn.Open strConn
rs1.Open strSQL1, cnn, adOpenForwardOnly, adLockReadOnly
Do While rs1.EOF = False
Sheets("Sheet1").Range("A" & i) = rs1!FIELDNAME1
'Sheets("Sheet1").Range("B" & i) = rs1!FIELDNAME2
'Sheets("Sheet1").Range("C" & i) = rs1!FIELDNAME3
'Sheets("Sheet1").Range("D" & i) = rs1!FIELDNAME4
'Sheets("Sheet1").Range("E" & i) = rs1!FIELDNAME5
'Sheets("Sheet1").Range("F" & i) = rs1!FIELDNAME6
'Sheets("Sheet1").Range("G" & i) = rs1!FIELDNAME7
'Sheets("Sheet1").Range("H" & i) = rs1!FIELDNAME8
i = i + 1
rs1.MoveNext
Loop
rs1.Close
cnn.Close
End Sub

"SAm" wrote:

Hi

How do i query an open recordset. currently i have a query and then i have
another query that queries it.

i will post the query and the recordset SQL

thanks,

sam


this is the query:

Code:
SELECT DISTINCT PPYearlyIndex.PgpPayGroup, PPYearlyIndex.PgpPeriodStartDate,
PPYearlyIndex.PgpPeriodEndDate
FROM PPYearlyIndex
WHERE (((PPYearlyIndex.PayperiodIndex) Between
[Forms]![RetentionAllFrm]![cboPayperiodIndexStart] And
[Forms]![RetentionAllFrm]![cboPayperiodIndexEnd]) AND
((PPYearlyIndex.PayperiodYear) Between
[Forms]![RetentionAllFrm]![cboPayperiodYearStart] And
[Forms]![RetentionAllFrm]![cboPayperiodYearEnd]));



now i have this recordset in my VBA:


Code:
strSQL = "SELECT PPAllFctsRetentionQry.PgpPayGroup,
Min(PPAllFctsRetentionQry.PgpPeriodStartDate) AS FirstStartDate,
Max(PPAllFctsRetentionQry.PgpPeriodStartDate) AS LastStartDate,
Min(PPAllFctsRetentionQry.PgpPeriodEndDate) AS FirstEndDate,
Max(PPAllFctsRetentionQry.PgpPeriodEndDate) AS LastEndDate " & _
" FROM PPAllFctsRetentionQry GROUP BY
PPAllFctsRetentionQry.PgpPayGroup;"

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Recordset.FindFirst argument not working... [email protected] Excel Worksheet Functions 0 March 20th 07 03:18 PM
pivot table from recordset - very slow performance [email protected] Charts and Charting in Excel 1 May 14th 06 04:05 PM
Save data retreived from query without saving query Anthony Excel Discussion (Misc queries) 0 January 25th 06 07:17 PM
Microsoft Query rejects "nz" function in Access Query Vaughan Excel Discussion (Misc queries) 0 May 4th 05 05:20 PM
return recordset Laurent M Excel Discussion (Misc queries) 4 January 26th 05 09:43 AM


All times are GMT +1. The time now is 07:35 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"