O
Ozzone
At least thats where i think the problem lies, here's the deal...i'm a n00b
and i need help heh
I have a primary key field that is a code - 2 numbers, a letter, then 2 more
numbers. So on my data entry form, i have code that auto-increments the last
2 digits by one, based off the previously entered value. Here's the code:
' global variable to store last used TreeID for this session
Dim gstrLastTreeID As String
Private Sub Form_Current()
' declare private variables
Dim strTempTreeID As String
Dim strBaseID As String
Dim intIncrementID As Integer
' assign the global to a private
strTempTreeID = gstrLastTreeID
' if TreeId has a value do nothing, if it's Null then...
If IsNull(Me![TreeID]) Then
' if the global has not been set yet then...
If strTempTreeID = "" Then
Exit Sub
'but if the global has been set...
Else
' then make the current TreeID one higher than the last one
strBaseID = Left$(strTempTreeID, Len(strTempTreeID) - 2)
intIncrementID = Val(Right(strTempTreeID, 2) + 1)
Me![TreeID] = strBaseID & IIf(intIncrementID < 10, "0" &
Format(intIncrementID), Format(intIncrementID))
End If
End If
End Sub
Private Sub Form_AfterUpdate()
' only update the global variable if TreeID has a value
If Not IsNull(Me![TreeID]) Then gstrLastTreeID = Me![TreeID]
End Sub
It works great until i need to delete a record that is at the EndOfFile, or
the last record. If i try to delete the last record, it just increments the
TreeId every time i hit delete, no delete confirmation or anything. I can
delete other records normally.
Any ideas? Thanks
btw...i tried putting the code in the TreeId text box events, had a
different problem... would only auto-increment if i typed the value in, just
tabbing out didnt trigger the AfterUpdate event
and i need help heh
I have a primary key field that is a code - 2 numbers, a letter, then 2 more
numbers. So on my data entry form, i have code that auto-increments the last
2 digits by one, based off the previously entered value. Here's the code:
' global variable to store last used TreeID for this session
Dim gstrLastTreeID As String
Private Sub Form_Current()
' declare private variables
Dim strTempTreeID As String
Dim strBaseID As String
Dim intIncrementID As Integer
' assign the global to a private
strTempTreeID = gstrLastTreeID
' if TreeId has a value do nothing, if it's Null then...
If IsNull(Me![TreeID]) Then
' if the global has not been set yet then...
If strTempTreeID = "" Then
Exit Sub
'but if the global has been set...
Else
' then make the current TreeID one higher than the last one
strBaseID = Left$(strTempTreeID, Len(strTempTreeID) - 2)
intIncrementID = Val(Right(strTempTreeID, 2) + 1)
Me![TreeID] = strBaseID & IIf(intIncrementID < 10, "0" &
Format(intIncrementID), Format(intIncrementID))
End If
End If
End Sub
Private Sub Form_AfterUpdate()
' only update the global variable if TreeID has a value
If Not IsNull(Me![TreeID]) Then gstrLastTreeID = Me![TreeID]
End Sub
It works great until i need to delete a record that is at the EndOfFile, or
the last record. If i try to delete the last record, it just increments the
TreeId every time i hit delete, no delete confirmation or anything. I can
delete other records normally.
Any ideas? Thanks
btw...i tried putting the code in the TreeId text box events, had a
different problem... would only auto-increment if i typed the value in, just
tabbing out didnt trigger the AfterUpdate event