My collection of things.

jKafer on the Net

November 27th, 2017 at 12:40 pm

Access (VBA) – reference control dynamically

So I will write my code as I need to but I always like being able to save key strokes.

I recently wanted to be able to copy text in a field to the clipboard to use it in another program (one that I could not link to the main program).  So I wrote this:

 

Private Sub SReqOrganizationName_DblClick(Cancel As Integer)
      Dim strCTL As String
      strCTL = Screen.ActiveControl.Name
      With Me.Controls(strCTL)
        If Len(.Value) Then
           .SelStart = 0
           .SelLength = Len(.Value)
           DoCmd.RunCommand acCmdCopy
        End If
      End With
End Sub

By using the with statement, I didn’t have to customize this for each field that I wanted to do this on.

The better thing would be to write this as a public command rather than put this is each fields DoubleClick command. But this works and works well too.

 

Tags: , ,
-

Comments are closed.


  • Count per Day

    • 23Visitors today:
    • 47Visitors per day:
    • 1Visitors currently online:
  • ScrapBook Software - MyMemoriesSuite
  • Latest Pins on Pinterest

    • These yoga poses can help you counteract your desk slouching.

    • Get this fast and easy tutorial for a baby quilt. It is made with beautiful batik fabrics. #quilting #batiks #diyproject #babyquilt ConnieKresin.com

    • grass green rocksteady quilt

    • A modern geometric quilt perfect for any nursery or home. Versatile enough to be used as a picnic or stroller blanket. It perfectly cosy and warm. Like all of our quilts, it has super soft minke backi More

    • blue ombre baby quilt - a fat quarter friendly pattern!

    • Лоскутная геометрия: Hunter's Star / Звезда охотника

    • kg17 -