Cursor position in subform

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • David57
    New Member
    • May 2016
    • 44

    Cursor position in subform

    Hello, I am facing a strange problem, I've looked everywhere for a solution but couldn't find any previous posts about it. I will try to explain as best as I can, but it's quite hard to describe.

    I have a subform with 5 fields. On the first of these fields “Date”I put in code triggered by On UpDate event so that after writing a new date in the subform some calculations are performed.
    So far everything works fine. My problem is that when I go back to a new record and focus the cursor again in the empty Date field, automatically the cursor moves to the first record (within the subform) of the same field (Date). It seems I can do nothing to stop it.
    Any help would be much appreciated.
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #2
    Does your code include a requery call? A requery call will set the cursor at the first record.

    Which event exactly are you using? I am confused as there is no On Update event. There is a before update, After update, and On Change.

    Comment

    • David57
      New Member
      • May 2016
      • 44

      #3
      Sorry I didn't explain correctly.
      The code does not include a requery call and the event I am using is After update.

      David

      Comment

      • jimatqsi
        Moderator Top Contributor
        • Oct 2006
        • 1288

        #4
        David, please explain more clearly what you are doing prior to the problem. It sounds like you edited the date of an existing record and that went well. Then you immediately clicked on the empty date field in a new row, not an existing row. Is that right?

        Are you doing anything in the sub-form's OnCurrent event or any other events of the Form (sub-form)?

        Comment

        • TheSmileyCoder
          Recognized Expert Moderator Top Contributor
          • Dec 2009
          • 2322

          #5
          Could you post the code of the afterupdate event? Do you have any other code related to that specific date control, such as an OnGotFocus event or?

          Comment

          • David57
            New Member
            • May 2016
            • 44

            #6
            I didn’t edit any existing date but I entered a new one. The problem arises when having finished putting data in all the fields, I focus the cursor in the field “Date” of a new empty record just to end the operation.
            Please understand that my knowledge of Access VBA is really rather basic. There is no other specific code related to the date control. The following is the code fired by the Date control.
            Code:
            Private Sub Data_AfterUpdate()
            Dim CstId As Single
            Dim SumPag1 As Single
            Dim SumPag2 As Single
            Dim SumPag3 As Single
            Dim Num As Byte
            CstId = Forms!Dipendenti!IDTblClienti
            Num = DLookup("PerPagam", "TblClienti", "IDTblClienti=" & CstId)
            Me![PerPag].Value = Num
            SumPag1 = Nz(DSum("VarDipendenti", "TblDipendenti", "Ditta=" & CstId), 0)
            SumPag2 = Nz(DSum("PrPagaMens", "TblDipendenti", "Ditta=" & CstId), 0)
            SumPag3 = SumPag1 * SumPag2
            mySQL = "UPDATE TblClienti"
            mySQL = mySQL & " SET TblClienti.ParcPerPghPrec =" & SumPag3 * Num
            mySQL = mySQL & " WHERE [IDTblClienti]=" & CstId
            DoCmd.SetWarnings False
            DoCmd.RunSQL mySQL
            DoCmd.SetWarnings True
            End Sub

            Comment

            Working...