Problems with Form_AfterUpdate...

G

Guest

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
 
G

Guest

i should have added that, when i open the form, i can delete the last record,
which means if the global variable is empty, it all works fine.

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??

Any and all input welcomed :)
 
G

Guest

I moved this thread to Forms_Coding, titled "Deleting last record causes key
field to increment..."

Sorry for the incorrect posting
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top