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