VBA to unlock and re-lock a control (1 Viewer)

Leo_Polla_Psemata

Registered User.
Local time
Today, 03:12
Joined
Mar 24, 2014
Messages
364
Hi there
I have two controls in a form that i have locked (enabled yes) .
In some cases, i have to copy paste manual data from one control to another while for other cases this is not needed.
To avoid manual copy paste, i have written the below code in which, i set focus on one control, copy, set focus on the other, unlock, paste, and lock again
However, the last command turns to yellow and doesn't lock the control ?? What's wrong ?


Code:
Private Sub TST2_DblClick(Cancel As Integer)
    
   Me!TST1.SetFocus
   DoCmd.RunCommand acCmdCopy
   Me!TST2.SetFocus
   Me!TST2.Locked = False
   DoCmd.RunCommand acCmdPaste
   Me!TST2.Locked = True

End Sub
 

bob fitz

AWF VIP
Local time
Today, 10:12
Joined
May 23, 2011
Messages
4,717
Perhaps you need to set the focus back to TST1 before locking TSB2
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:12
Joined
May 7, 2009
Messages
19,175
there is no need to Unlock the control, you just assign the value to your textbox:
Code:
Private Sub TST2_DblClick(Cancel As Integer)
    
   Me!TST2 = Me!TST1

End Sub
 

Gasman

Enthusiastic Amateur
Local time
Today, 10:12
Joined
Sep 21, 2011
Messages
14,050
Hi there
I have two controls in a form that i have locked (enabled yes) .
In some cases, i have to copy paste manual data from one control to another while for other cases this is not needed.
To avoid manual copy paste, i have written the below code in which, i set focus on one control, copy, set focus on the other, unlock, paste, and lock again
However, the last command turns to yellow and doesn't lock the control ?? What's wrong ?


Code:
Private Sub TST2_DblClick(Cancel As Integer)
   
   Me!TST1.SetFocus
   DoCmd.RunCommand acCmdCopy
   Me!TST2.SetFocus
   Me!TST2.Locked = False
   DoCmd.RunCommand acCmdPaste
   Me!TST2.Locked = True

End Sub
If it turned to yellow, surely it would have generated an error message? :(
 

Users who are viewing this thread

Top Bottom