Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 23rd, 2009, 09:23 AM
Registered User
 
Join Date: Oct 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Run-time error '3296': Join expression not supported.

Hello,
Please could someone help me?
I have built 2 Access queries, one is a select query that gathers all of the data required and the second is a crosstab that uses the results from the first query and populates it into the correct format needed (I.E. all of the dates as column headers)
Both of these queries run fine in Access but when trying to put them into a module I am getting the "Run-time error '3296': Join expression not supported." (Bit of code below in BOLD)
Here is the code used in the module:
As you can see I have put in a Do While loop in to run the queries using 'Agent' as a parameter.
If anyone can help I would be very grafetful as I know have no hair and no skin left on my teeth!

Thanks

Code:
Option Compare Database
Option Explicit
Sub Productivity_Daily_Report()

Dim rsResources As Recordset
Dim rsFirst As Recordset
Dim rsSecond As Recordset

Dim sqlResources As String
Dim sqlFirst As String
Dim sqlSecond As String

Dim app As New Excel.Application, excelws
Dim Agent As String

sqlResources = "Select * from Resources;"
Set rsResources = CurrentDb.OpenRecordset(sqlResources)

If rsResources.EOF And rsResources.BOF Then
    Beep
    MsgBox "No records!"
    rsResources.Close
    GoTo end_it
End If

Set app = CreateObject("Excel.application")

Set excelws = app.Application
With excelws
.Visible = True

Do While Not rsResources.EOF

Agent = rsResources!FullName

app.Workbooks.Open "Z:\Productivity\Blank.xls", , True

'*********** First Query ***************

sqlFirst = "SELECT Main.FPO, Main.Rec_Date, AI_Queue.[Task Name], Count(Main.MainId) AS CountOfMainId" & vbCrLf & _
"FROM Production_Selection, Main INNER JOIN AI_Queue ON Main.[A&I Queue] = AI_Queue.[A&I Queue]" & vbCrLf & _
"WHERE (((Weekday([Main].[Rec_Date]))<>7 And (Weekday([Main].[Rec_Date]))<>1) AND ((Main.Rec_Date) Between [StartDate] And [EndDate]) AND ((Main.FPO)='" & Agent & "'))" & vbCrLf & _
"GROUP BY Main.FPO, Main.Rec_Date, AI_Queue.[Task Name]"

Set rsFirst = CurrentDb.OpenRecordset(sqlFirst, dbOpenDynaset)

'************* Second Query ***************

sqlSecond = "TRANSFORM Sum(rsFirst!CountOfMainId) AS SumOfCountOfMainId" & vbCrLf & _
"SELECT rsFirst!FPO, rsFirst![Task Name]" & vbCrLf & _
"FROM Days_Month LEFT JOIN rsFirst ON Days_Month.Date = rsFirst!Rec_Date" & vbCrLf & _
"GROUP BY rsFirst!FPO, rsFirst![Task Name]" & vbCrLf & _
"PIVOT Days_Month.Date"

Set rsSecond = CurrentDb.OpenRecordset(sqlSecond, dbOpenDynaset)

.Range("A2").copyfromrecordset rsSecond

excelws.activeworkbook.SaveAs ("Z:\Productivity\BlankReport_" & rsResources!FullName & ".xls")
excelws.activeworkbook.Close

rsResources.MoveNext
Loop
End With
Set excelws = Nothing
Set app = Nothing

rsResources.Close

end_it:
Set rsResources = Nothing
End Sub





Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Query Error & Run-Time Error 3022 DavidWE Access 1 July 31st, 2008 11:17 AM
Runtime error '3296' ayazhoda Access VBA 1 June 7th, 2007 12:20 PM
run-time error(s) Chacko C++ Programming 0 March 4th, 2007 02:28 PM
run time error ashishroyk Java GUI 0 October 8th, 2004 01:42 AM
RUN-TIME ERROR compcad Beginning VB 6 2 May 21st, 2004 02:01 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.