debugging code

sarahb845

Registered User.
Local time
Today, 00:38
Joined
Jun 19, 2002
Messages
43
I have inherited this database with the following code, and up until today, it worked. Now, when the code is executed I get an "Error 3265 Item not found in this collection." I really have no idea what this means. And, I don't really know where in the code it gets the error (a user found it while in the GUI); I don't know how to debug code.

I don't know if this matters, but I split the database a couple of days ago.... Don't remember the error after splitting, but maybe I never tested this area.

Any help would be greatly appreciated!!!!!

---------------

Public Sub SetReportVariables(strReportName As String)
'This procedure sets the form display variables for the
'report name provided
On Error GoTo ErrHandler

'Declare procedure variables
Dim djetDB As Database, rsnpReports As DAO.Recordset, _
strCriteria As String

'Set procedure variables
Set djetDB = CurrentDb
Set rsnpReports = djetDB.OpenRecordset("tblReports", dbOpenSnapshot)
strCriteria = "ReportName = '" & strReportName & "'"

'Read the recordset
rsnpReports.MoveLast

'Find the specified report and set display variables for that report
With rsnpReports
.FindFirst strCriteria
blnSelectOperUnit = !SelectOperatingUnit
blnSelectDiv = !SelectDivs
blnSelectLoc = !SelectLocs
blnSelectDept = !SelectDepts
blnSelectJobTitle = !SelectJobs
blnSelectEmplID = !SelectEmpID
blnSelectName = !SelectNames
blnSelectDate = !SelectDate
blnSelectMonth = !SelectMonth
'close recordset
.Close
End With

ExitSub:
Exit Sub

ErrHandler:
MsgBox Err & " " & Err.Description
Resume ExitSub

End Sub
 
Debugging code is actually much easier then you think.

You have several methods available to you.

1. Place a Break Point on this Line:

Public Sub SetReportVariables(strReportName As String)

"Debug Menu", "Toggle Breakpoint"

or

Click the Grey bar next to the line.


2. Change the ErrorHandler Rutine (For Debugging only, make sure you put it back before you redistribute)

ErrHandler:
Stop 'This will stop the code on this line
Resume 0 'This will return you to the offending line.
'MsgBox Err & " " & Err.Description
'Resume ExitSub



Once in this mode you will be able to use the Debug Menu of Hot Keys to step thru the code. You also have the View Menu which has the Immediate window, the Locals Window and the Call Stack Window.

Immediate Window is a place you can run a line of code to see what the results are going to be or just print out the value of a variable.

Locals Window shows you all the variables and what they are set to.

Call Stack Window shows you where this block of code was run from.
 
Your error means that you are attempting to reference a field in a recordset and it does not exist. You either have the wrong recordset, or your field name is misspelled.
 
Thanks to Travis!
I have been trying to figure out how to debug for a while, but because I hadn't changed my error handling, I never could figure out what was wrong with the code. I really needed those instructions to get me through it.


And, thanks to llkhoutx!
You were right - I was referencing a field that no longer existed in the table. I didn't think I had deleted it in the user's db yet (just my working copy), so that is why I got the error.

thanks again!
sarah
 

Users who are viewing this thread

Back
Top Bottom