A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Database Design
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Problems with Form_AfterUpdate...



 
 
Thread Tools Display Modes
  #1  
Old February 21st, 2005, 03:39 AM
Ozzone
external usenet poster
 
Posts: n/a
Default Problems with Form_AfterUpdate...

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

  #2  
Old February 21st, 2005, 03:49 AM
Ozzone
external usenet poster
 
Posts: n/a
Default

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


  #3  
Old February 21st, 2005, 04:05 AM
Ozzone
external usenet poster
 
Posts: n/a
Default

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

Sorry for the incorrect posting


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Disconnect Problems with Sending Email jeff General Discussion 4 January 18th, 2005 05:36 PM
File Corruption problems Frustrated Page Layout 2 December 3rd, 2004 09:47 PM
Video Problems Robert Powerpoint 4 August 19th, 2004 04:42 PM
OE 6 Problems Rick A. Outlook Express 2 July 16th, 2004 02:21 PM
Publisher 2003 web page problems LoBo Designs Publisher 1 June 17th, 2004 05:01 AM


All times are GMT +1. The time now is 11:45 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.