O
Ozzone
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.
When i first open the form, i can delete the last record, which means if the
global variable is empty, it all works fine.
I tried putting the code in the TreeId text box events Enter and AfterUpdate
but had a different problem... would only auto-increment if i typed the value
in, just
tabbing out didnt trigger the AfterUpdate event. So every other record i had
to type in the value.
im not sure why its behaving in this manner, but when i hit delete, the only
event being called (as fas as i can tell), is the Form_AfterUpdate. Maybe i
need to move that code to a different event?? I mention TreeId being a
primary key field because i have a feeling that has something to do with it
too.
Any and all input welcomed
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.
When i first open the form, i can delete the last record, which means if the
global variable is empty, it all works fine.
I tried putting the code in the TreeId text box events Enter and AfterUpdate
but had a different problem... would only auto-increment if i typed the value
in, just
tabbing out didnt trigger the AfterUpdate event. So every other record i had
to type in the value.
im not sure why its behaving in this manner, but when i hit delete, the only
event being called (as fas as i can tell), is the Form_AfterUpdate. Maybe i
need to move that code to a different event?? I mention TreeId being a
primary key field because i have a feeling that has something to do with it
too.
Any and all input welcomed