Results 1 to 2 of 2
  1. #1
    masoud_sedighy is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Dec 2011
    Posts
    78

    Just first record of the form (data sheet view) will be updated by code

    In the form (data sheet view) I have, I put a click event for each field in the form like below, now problem is value of selected record of form will not be updated and just first record will be updated.
    For example I have used below code for updating value of field of selected record ,for example value if (Item_Name="test1) and I want to change to "test2" and used below code but It cannot change value , just goes to first record, and value of first record changes.
    I can manually change value of each field but by code no? Just first record changes.

    Code:
    Dim ct As Control
        Dim Cnt As Long, Rws As Long
        Dim Pos1 As Long, Pos2 As Long
       
        Pos1 = Me.Recordset.AbsolutePosition
       
        Set ct = ActiveControl
       
       
        ' Clear other selections if Ctrl or Shift key
        ' is not simultaneously pressed.
     
       If CtrlPressed = 0 And ShiftPressed = 0 Then
            P_ClearSelections
            Me.Recordset.AbsolutePosition = Pos1
          
          
           
            MsgBox Me.Item_Name -----(returned value is "test1")
            Me.Item_Name = "test2"
            MsgBox Me.Item_Name-----(returned value is "test1")
     
          
           
           
           
            ct.SetFocus
            GoTo ExitPoint
        End If
    Complete code:

    Code:
    Private Sub Item_Name_Click()
    P_Click
    End Sub
    Code:
    Private Sub P_Click()
        On Error Resume Next
        Dim ct As Control
        Dim Cnt As Long, Rws As Long
        Dim Pos1 As Long, Pos2 As Long
       
        Pos1 = Me.Recordset.AbsolutePosition
       
        Set ct = ActiveControl
       
       
        ' Clear other selections if Ctrl or Shift key
        ' is not simultaneously pressed.
        If CtrlPressed = 0 And ShiftPressed = 0 Then
            P_ClearSelections
            Me.Recordset.AbsolutePosition = Pos1
          
          
           
            Me.IsSelected = True
            MsgBox Me.Item_Name
            Me.Item_Name = "support"
            MsgBox Me.Item_Name
          
           
           
           
            ct.SetFocus
            GoTo ExitPoint
        End If
       
        If ShiftPressed > 0 Then
            Rws = Me.SelHeight
            If Rws > 1 Then
                Pos2 = Me.SelTop - 1
                For Cnt = Pos2 To Pos2 + Rws - 1
                    Me.Recordset.AbsolutePosition = Cnt
                    Me.IsSelected = True
                Next
            End If
            GoTo ExitPoint
        End If
       
        Me.IsSelected = True
       
    ExitPoint:
        ' Save the status
        Me.Dirty = False
        ' Update display in SF_Selected
        Me.Parent("SF_Selected").Requery
       
        ActiveControl.SelLength = 0
       
        Set ct = Nothing
        On Error GoTo 0
    End Sub


  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Have you step debugged? Follow code as it executes, identify where it deviates from expected behavior, fix, debug.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 19
    Last Post: 04-23-2013, 10:08 AM
  2. change heading in data sheet view
    By sharad.rt in forum Forms
    Replies: 4
    Last Post: 07-21-2012, 12:54 PM
  3. Replies: 1
    Last Post: 07-13-2012, 08:50 AM
  4. Replies: 1
    Last Post: 04-10-2012, 12:34 PM
  5. Replies: 9
    Last Post: 03-24-2009, 09:19 PM

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