WLoftus
asked on
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.AddNew()
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").Val ue = intDaysinProcess
myRS5.Update()
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.
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.AddNew()
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").Val
myRS5.Update()
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.