• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3003
  • Last Modified:

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

0
chtullu135
Asked:
chtullu135
  • 7
  • 5
1 Solution
 
Jeffrey CoachmanCommented:
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



0
 
Jeffrey CoachmanCommented:
...and NewAccrualCheckReportRecordSource is defined as a String...
0
 
chtullu135Author Commented:
Yes I confirmed the variable is global and that it is a string.  Attached is the screen print of the error message
Error.JPG
0
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
chtullu135Author Commented:
I'm also setting the recordsource of the report on the open event at runtime
0
 
Jeffrey CoachmanCommented:
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

0
 
Jeffrey CoachmanCommented:
Also post the actual SQL that Debug is returning...
0
 
Jeffrey CoachmanCommented:
FWIW, you should always build your SQL incrementally, and test it along the way.

This way when it breaks, you know that it was caused by the last thing you did.

This is far more efficeint than posting a Large SQL string and trying to find the one minor syntax mistake.
Make sense...?

;-)
0
 
chtullu135Author Commented:
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

0
 
Jeffrey CoachmanCommented:
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...
0
 
chtullu135Author Commented:
I'm doing that right now
0
 
chtullu135Author Commented:
I found the problem.  I was missing a pair of parenthesis that is used to enclose the first inner join.  Thanks for the help.
0
 
Jeffrey CoachmanCommented:
Great!

Enjoy the weekend.

;-)
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now