Results 1 to 2 of 2
  1. #1
    Fish218 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Feb 2012
    Posts
    68

    Why does this code work in 'On Key Down' and not in 'After Update'

    Also if there's a way to "clean it up" let me know...I'm somewhat new to VBA and don't know all the great shortcuts in code...

    Private Sub PoundsCaught_KeyDown(KeyCode As Integer, Shift As Integer)
    On Error Resume Next
    Select Case KeyCode
    'If after entering data into PoundsCaught you press the down arrow...
    Case vbKeyDown
    'This is code for what happens in the Day field
    If Not Me.NewRecord Then Exit Sub
    If Not (IsNull(Me![Text34].Tag) Or Me![Text34].Tag = "") Then
    Me![Text34].Value = Me![Text34].Tag
    [LiftDate] = [Forms]![frmCOMMERCIAL2]![Combo9] & "/" & [Text34] & "/" & Right([Forms]![frmCOMMERCIAL2]![Combo11], 2)
    Me![Text34].Tag = Me![Text34].Value + 1
    [Text34] = Null
    End If
    'This is code for what happens in the FeetFromSurface field...
    If Not Me.NewRecord Then Exit Sub
    If Not (IsNull(Me![FeetFromSurface].Tag) Or Me![FeetFromSurface].Tag = "") Then
    Me![FeetFromSurface].Value = Me![FeetFromSurface].Tag
    End If
    'This is code for what happens in the NetLength field...
    If Not Me.NewRecord Then Exit Sub
    If Not (IsNull(Me![NetLength].Tag) Or Me![NetLength].Tag = "") Then
    Me![NetLength].Value = Me![NetLength].Tag
    End If
    'This is code for what happens in the NightsSet field...
    If Not Me.NewRecord Then Exit Sub
    If Not (IsNull(Me![NightsSet].Tag) Or Me![NightsSet].Tag = "") Then
    Me![NightsSet].Value = Me![NightsSet].Tag
    End If
    'This is code for filling in the appropriate fields with data from previous record...
    [Text34].Value = [Text34].Tag + 1
    [FeetFromSurface].Value = [FeetFromSurface].Tag
    [NetLength].Value = [NetLength].Tag


    [NightsSet].Value = [NightsSet].Tag
    [Text34] = Null
    End Select
    End Sub

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    The AfterUpdate event is *not* passed the KeyCode as is the KeyDown event, among other things.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. My query code doesn't work
    By blacksaibot in forum Programming
    Replies: 2
    Last Post: 03-08-2012, 02:59 PM
  2. Replies: 4
    Last Post: 01-25-2012, 04:38 AM
  3. Replies: 3
    Last Post: 12-28-2010, 12:42 PM
  4. Code does not work in 64 Bit Access 2010
    By mwolfod in forum Programming
    Replies: 26
    Last Post: 12-12-2010, 04:39 PM
  5. VBA Code To Work With MySQL
    By botts121 in forum Programming
    Replies: 0
    Last Post: 07-08-2009, 08:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums