So I have these two AfterUpdate events that I use to grab the counts of fish by year, collector, and assessment. These AU events automatically add 1 and the Fish Number [FishNum] autoincrements with each new record. The problem is the first new record added starts off at 0002 then the next record is 0002 then 0003 then 0004 and so on. I'm not sure why it's not correctly putting in 0001 on the first new record. I checked the query and it runs properly. Any help would be greatly appreciated.
Code:
Private Sub FishNum_AfterUpdate()
Dim varYear As Integer
Dim varAssessment
Dim varCollector As Integer
Dim varFishCount
varYear = [Forms]![frmCommercial2]![Form1]![Text788]
varAssessment = [Forms]![frmCommercial2]![Form1]![Text796]
varCollector = [Forms]![frmCommercial2]![Form1]![Combo746]
varFishCount = DLookup("[CountofIndividualFishID]", "qry2012", "[CollectionYear]=" & varYear & " And [CollectorID]= " & varCollector & " And [AssessCodeID]=" & varAssessment)
If (IsNull(varFishCount)) Then
[Text56] = 0
[Text58] = 1
ElseIf Not (IsNull(varFishCount)) Then
[Text56] = varFishCount
[Text58] = varFishCount + 1
End If
[FishNum] = varYear & "-" & [Forms]![frmCommercial2]![Form1]![Text796] & "-" & [Forms]![frmCommercial2]![Form1]![Combo746] & (Format([Text58], "0000"))
End Sub
Private Sub Length__in__AfterUpdate()
Dim varYear As Integer
Dim varAssessment
Dim varCollector As Integer
Dim varFishCount
varYear = [Forms]![frmCommercial2]![Form1]![Text788]
varAssessment = [Forms]![frmCommercial2]![Form1]![Text796]
varCollector = [Forms]![frmCommercial2]![Form1]![Combo746]
varFishCount = DLookup("[CountofIndividualFishID]", "qry2012", "[CollectionYear]=" & varYear & " And [CollectorID]=" & varCollector & " And [AssessCodeID]=" & varAssessment)
If (IsNull(varFishCount)) Then
[Forms]![frmCommercial2]![Form1]![subIndividualOther1]![Text56] = 0
[Forms]![frmCommercial2]![Form1]![subIndividualOther1]![Text58] = 1
ElseIf Not (IsNull(varFishCount)) Then
[Text56] = varFishCount
[Text58] = varFishCount + 1
End If
[FishNum] = varYear & "-" & [Forms]![frmCommercial2]![Form1]![Text796] & "-" & [Forms]![frmCommercial2]![Form1]![Combo746] & "-" & (Format([Text58], "0000"))
[DataEntryID] = [Forms]![frmCommercial2]![Combo23]
End Sub