Link to home
Start Free TrialLog in
Avatar of Juan Velasquez
Juan VelasquezFlag for United States of America

asked on

2580 Runtime error when setting record source of report

I am getting a runtime error of 2580 stating that the recordsource does not exist when when trying to set the report recordsource at runtime via
me.recordsource = NewAccrualCheckReportRecordSource where NewAccrualCheckReportRecordSource is a global variable that is set via the attached code.  I am working in Access 2007
strSql = "SELECT project.[Task Order], [OBS Master].OBS, [Lname] & '" & ", " & "' " _
& " & [Fname] AS Name, [OBS Master].Fname, [OBS Master].Lname, " _
& "project.Posted AS WeekEnding, project.Workhours AS RegularHours, " _
& "[FY11B]+[FY11OH] AS FY11Rate, [RegularHours]*[FY11Rate] AS RegularPay, " _
& "project.Overtime AS OvertimeHours, [OT11B]+[OT11OH] AS FY11otRate, " _
& "[OvertimeHours]*[FY11otRate] AS OvertimePay, [OBS Master].ODC3 AS FY11odcRate, " _
& "[OBS Master].Fee2 AS FY11FeeRate, project.[Charge #] AS ChargeNumber, " _
& "[RegularPay]+[OvertimePay] AS TotalPay, [OBS Master].FY11B, [OBS Master].FY11OH, " _
& "[OBS Master].OT11B, [OBS Master].OT11OH, project.Comments, project.locked, " _
& "project.source, [OBS Master].[Company ]FROM Period " _
& "INNER JOIN project " _
& "ON Period.[Week Ending] = project.Posted " _
& "INNER JOIN [OBS Master] " _
& "ON project.OBS = [OBS Master].OBS " _
& "WHERE project.locked = False AND project.source Like '" & " a " & "'"


Debug.Print strSql
NewAccrualCheckReportRecordSource = strSql
  
    MsgBox "Run Report"
    DoCmd.OpenReport "New Accrual Check"

Open in new window

Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

So how are you actually trying to load the recordset into the report?

Something like this on the open event of the Report should work if NewAccrualCheckReportRecordSource is *Truly* defined as Global (and is spelled correctly...)...

If NewAccrualCheckReportRecordSource<>"" Then
    Me.recordSource=NewAccrualCheckReportRecordSource
end if

JeffCoachman



...and NewAccrualCheckReportRecordSource is defined as a String...
Avatar of Juan Velasquez

ASKER

Yes I confirmed the variable is global and that it is a string.  Attached is the screen print of the error message
Error.JPG
I'm also setting the recordsource of the report on the open event at runtime
Then you must make sure the Global Variable is a valid SQL string, (That  produces records.)

For example you can set the SQL to:
strSQL="SELECT Two All Beef Patties FROM McDonald's"
Or even:
strSQL="The Frog is on the Pond"

...and you will get the same error you are getting
(Because neither is a correctly formed SQL statement.


So open the code and copy the Debug SQL and paste it into a new query and see if it runs...

If not, then your error is in how you are building the SQL...

JeffCoachman

Also post the actual SQL that Debug is returning...
ASKER CERTIFIED SOLUTION
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I went ahead and did that and the query failed on
ON Period.[Week Ending] = project.Posted INNER JOIN [OBS Master] ON project.OBS = [OBS Master].OBS

However, it looks right.  I did change the apostrophes to commas for that encapsulated the literals
SELECT project.[Task Order], [OBS Master].OBS, [Lname] & ", "  & [Fname] AS Name, [OBS Master].Fname, [OBS Master].Lname, project.Posted AS WeekEnding, project.Workhours AS RegularHours, [FY11B]+[FY11OH] AS FY11Rate, [RegularHours]*[FY11Rate] AS RegularPay, project.Overtime AS OvertimeHours, [OT11B]+[OT11OH] AS FY11otRate, [OvertimeHours]*[FY11otRate] AS OvertimePay, [OBS Master].ODC3 AS FY11odcRate, [OBS Master].Fee2 AS FY11FeeRate, project.[Charge #] AS ChargeNumber, [RegularPay]+[OvertimePay] AS TotalPay, [OBS Master].FY11B, [OBS Master].FY11OH, [OBS Master].OT11B, [OBS Master].OT11OH, project.Comments, project.locked, project.source, [OBS Master].[Company ] FROM Period INNER JOIN project ON Period.[Week Ending] = project.Posted INNER JOIN [OBS Master] ON project.OBS = [OBS Master].OBS WHERE project.locked = False AND project.source Like" a "

Open in new window

Then what I do in these situations is to simply build the query in Access in the Query Grid.
Then at least you can see what the correct syntax should be...
I'm doing that right now
I found the problem.  I was missing a pair of parenthesis that is used to enclose the first inner join.  Thanks for the help.
Great!

Enjoy the weekend.

;-)