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

    • 10Visitors today:
    • 33Visitors per day:
    • 0Visitors currently online:
  • ScrapBook Software - MyMemoriesSuite
  • Latest Pins on Pinterest

    • @suppose_quilts I totally OMG'd outloud when I saw this quilt! I love it! By @suppose_quilts "It just snowed here but we're pretending it's spring. Pattern: Amsterdam, free at cloud9fabrics.com. Fabric: Pam Kitty Garden" via @PhotoRepost_app

    • Striking Strip Quilts: 16 Amazing Patterns for 2 1/2"-Strip Lovers: Kate Henderson: Jelly roll tulip quilt. Flower quilt pattern. affiliate link.

    • Fall Table Runner | from Marta with love http://frommartawithlove.com/fall-table-runner/

    • Scrappy Butterfly Baby Quilt Tutorial | Let your imagination take flight with this baby quilt!

    • All In A Row Again!

    • Feathered stars are fun to quilt! #freemotionquilting #longarmquilting #quiltedthistle

    • Westalee - Curly Q's

    • 18 Easy tutorials for making your own fabric labels at home. Click through to browse the list! DIY Crush

    • 6a0120a5f3f908970b015437f40faf970c-pi 3,312×4,416 pixels