We help IT Professionals succeed at work.

Not Understood Warning Message

VB2010 - VB2010
ACCDB data file

I am receiving the following warning message.  I do understand what the message is saying, but I don't understand how to resolve the warning message.  The message is:

The type for variable 'icnt' will not be inferred because it is bound to a field in an enclosing scope. Either change the name of 'icnt', or use the fully qualified name (for example, 'Me.icnt' or 'MyBase.icnt').      

The code that generates the warning message follows:
If bolFoundItem = True And bolfounditem2 = True And bolfounditem3 = True Then
                        icnt = 0
                        For icnt = 1 To iCount
                            myRS5("Invoice Number").Value = myRS("Invoice Number").Value
                            myRS5("Contract number").Value = myRS("Contract Number").Value
                            myRS5("Contractor Name").Value = wrkContractorName
                            myRS5("Date Received").Value = myRS("Stamped date").Value
                            myRS5("Date to GTR").Value = myRS("Date to GTR").Value
                            myRS5("GTR Name").Value = wrkGTRName
                            myRS5("Acceptance Date").Value = myRS("Acceptance Date")
                            myRS5("Program Code").Value = arrPA(icnt - 1)
                            myRS5("Invoice Amount").Value = arrPAA(icnt - 1)
                            myRS5("DaysInProcess").Value = intDaysinProcess
                        Next icnt
                    End If

This is nothing more than a simple loop.  The purpose is to write unique records for up to 5 line items in an invoice.  
Watch Question

Most Valuable Expert 2012
Top Expert 2014
Do you declare icnt somewhere? You can also change

  icnt = 0
                        For icnt = 1 To iCount


For icnt As Integer = 1 To iCount
Awarded 2010
Top Expert 2013

What happened is apparently you declared icnt earlier and it's still in scope. My guess is you declared it as something else.
I wouldn't expect redeclaring it to work.
If you declared it previously right before a loop, declare it in both places inside the loops (as CodeCruiser suggested) and the scoping will be fixed so the won't shadow each other.

If it was previously declared as an integer, then why would it complain at all? Are you using Option Explicit and giving all your variables types? You should be.


icnt was a public declared variable to be used in other places.  The goal was to use it for additional needs, but basically codecruiser resolution resolved the issue.