I have some VBA that I am using in a module in access. My Data looks like,
SectionID------Left_Img
---------------------------------
---19--------------394
---26--------------781
---83--------------842
---83--------------450
---83--------------453
---83--------------456
--104--------------621
--104--------------622
I need to generate a sample number for these numbers. The data should look like this,
SectionID------Left_Img-----Sample--
--------------------------------------------------
---19--------------394-----------------1
---26--------------781-----------------1
---83--------------842-----------------1
---83--------------450-----------------2
---83--------------453-----------------3
---83--------------456-----------------4
--104--------------621-----------------1
--104--------------622-----------------2
I have written some vba but it is returning the following results,
SectionID------Left_Img-----Sample--
--------------------------------------------------
---19--------------394-----------------1
---26--------------781-----------------2
---83--------------842-----------------3
---83--------------450-----------------4
---83--------------453-----------------5
---83--------------456-----------------6
--104--------------621-----------------7
--104--------------622-----------------8
Here is the VBA I wrote. I should mention this is my first time using VB so speak slowly when replying,
Option Compare Database
Option Explicit
Public wIMG As String
Public wSEC As String
Public wRuningCount As Long
Function GetRunCount(Left_Img) As Long
Dim sectionid As String
If wSEC = sectionid And wIMG = Left_Img Then
wRuningCount = wRuningCount
wSEC = sectionid
wIMG = Left_Img
Else<b>
If wSEC = sectionid And wIMG <> Left_Img Then
wSEC = sectionid
wIMG = Left_Img
wRuningCount = wRuningCount + 1
Else
If wSEC <> sectionid Then
wSEC = sectionid
wIMG = Left_Img
wRuningCount = 1
End If
End If
End If
GetRunCount = wRuningCount
End Function
Anyone have any idea what this isn't working as I expect?
Thanks for your time.