Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2016
    Posts
    1

    Unanswered: Create one public sub that updates different forms with common controls

    I currently have 4 different forms, each pointing to their own tables, each form with the identical 2 controls/fields (DateMod and UserMod) that I want updated everytime the form is dirtied.

    the forms are
    frmNote
    frmRaidq
    frmAttachment
    frmTask

    they each currently contain the same vba code:

    Private Sub Form_Dirty(Cancel As Integer)
    UserMod = GetUserName
    DateMod = Now()
    UserModDisp.Requery
    End Sub

    It works fine. However, I want to write one public sub with an argument that I can call from the form that does the same thing, so I don't have duplicative code.

    Example UpdateModData("frmNote")

    I've only been programming a short while, so I appreciate your patience and help.

  2. #2
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    630
    Provided Answers: 34
    pass the objects to the routine

    Code:
    Private Sub Form_Dirty(Cancel As Integer)
      UpdModData usermod, datemod, usermodDisp
    End Sub
    
    
    sub UpdModData(ptxtUsr as textbox, ptxtDte as textbox, pObj)
      ptxtUsr = GetUserName
      ptxtDte = Now()
      pObj.Requery
    end sub

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •