Item not found in collection?

Hey guys - when using this code, we get an error "item not found in collection"

Why?
Private Sub ExecuteDrawing_Click()

    StatusBox.Value = "Starting Drawing..."
    Me.Repaint
    
    StatusBox.Value = StatusBox.Value & vbCrLf & vbCrLf & "Backing Up and Deleting DrawingWinners Table"
    Me.Repaint
    
    DoCmd.SetWarnings False
    'On Error Resume Next
    DoCmd.RunSQL "SELECT * INTO [6050c__DrawingWinners--Backup] FROM [6050c__DrawingWinners];"
    DoCmd.SetWarnings True
    
    StatusBox.Value = StatusBox.Value & vbCrLf & vbCrLf & "Generating Drawing Winners"
    Me.Repaint
    
    DoCmd.SetWarnings False
    DoCmd.OpenQuery "6050a_Drawing"
    DoCmd.OpenQuery "6050b_Drawing"
    DoCmd.OpenQuery "6050c_DrawingWinners"
    DoCmd.SetWarnings True
    
    CurrentDb.OpenRecordset ("6050c__DrawingWinners")
    
    StatusBox.Value = StatusBox.Value & vbCrLf & vbCrLf & "Complete: " & CurrentDb.TableDefs(“6050c__DrawingWinners”).RecordCount & " winners drawn."
    Me.Repaint
    Me.Repaint
    
End Sub

Open in new window

jn1480Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jn1480Author Commented:
Sorry - should've noted it is on this line that it occurs:


StatusBox.Value = StatusBox.Value & vbCrLf & vbCrLf & "Complete: " & CurrentDb.TableDefs(“6050c__DrawingWinners”).RecordCount & " winners drawn."

Open in new window

0
MuffyBunnyCommented:
I notice that on line 20 6050c_DrawingWinners only has 1 underscore, but on lines 23 and 25, you used 2 underscores.
0
jn1480Author Commented:
Yes - line 20 refers to running the query that builds the table with the (almost) same name.
The query has one underscore and builds a table with the same name, but with two underscores.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

MuffyBunnyCommented:
I'm going to say that RecordCount is your most likely suspect then. It's extremely flakey. It's only available when using certain cursorTypes for your database calls. The default cursorType, which happens when you don't specify one at all is Forward-Only and it will not give you RecordCount.

Here's a decent & short article on that topic. It's an ASP article, but the code samples given are VBscript
http://classicasp.aspfaq.com/general/why-does-recordcount-return-as-1.html

Another possibility is that your query isn't returning any results. Check for population with something like:
If Not CurrentDb.TableDefs(“6050c__DrawingWinners”).EOF Then

Open in new window


0
jn1480Author Commented:
thanks for the assistance!
...but could I beg you to help out a newbie, and help me figure out how to use this in my code?
I just tried a few of those items listed in your linked article, and nothing works.

Help?
0
MuffyBunnyCommented:
Try replacing lines 23 - 25 with the following code

Set rst = CurrentDb.OpenRecordset ("6050c__DrawingWinners")
If rst.RecordCount = 0 Then
	' the recordset is empty
	rowcnt = 0
Else
	rst.MoveLast
	rst.MoveFirst
	rowcnt = rst.RecordCount
End If

StatusBox.Value = StatusBox.Value & vbCrLf & vbCrLf & "Complete: " & rowcnt & " winners drawn."

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jn1480Author Commented:
PERFECT - and thanks for the extra training!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.