GK in the UK
Registered User.
- Local time
- Today, 20:35
- Joined
- Dec 20, 2017
- Messages
- 281
I have this code repeated for a number of bound controls (with the respective control names obviously). It copies control data from a datasheet into the equivalent control for a new record.
Is there a way to build this into a function? I made a brief start but whilst I can get the name of the current control, I don't know if there is a way to pass the KeyCode into the function (from the control property event property sheet). Also, the line frmDsheet.strActiveCtl doesn't seem to be a valid reference, even though the explicit code in my working routine works.
So I'm looking for a way to call the function from the property sheet event tab, something like this:
I get an error 'The object doesn't contain the automation object 'KeyCode'
Edit: KeyDown probably not a good name for the function so I renamed it KeyDownTest but I get the same error
Code:
Private Sub tlDescription1_KeyDown(KeyCode As Integer, Shift As Integer)
' copy datasheet line detail to the new line
' whichever line is highlighted in the datasheet,
' copy the equivalent field to the new transaction line
If KeyCode = CopyLineKey And bGotCopies Then
tlDescription1 = frmDsheet.tlDescription1
KeyCode = vbKeyReturn ' then simulate the return key
End If
End Sub
So I'm looking for a way to call the function from the property sheet event tab, something like this:
Code:
= KeyDown (KeyCode, text as textbox)
Code:
' experimental code follows:
Private Function KeyDown(KeyCode As Integer, text As TextBox)
' usage: =KeyDown (KeyCode, tlDescription1)
' copy datasheet line detail to the new line
Dim strActiveCtl As String
strActiveCtl = Screen.ActiveControl.Name
' code to fetch KeyCode from the event, and pass it into this function
If KeyCode = CopyLineKey And bGotCopies Then
text = frmDsheet.strActiveCtl ' the underlying datasheet that we want to copy from
KeyCode = vbKeyReturn ' then simulate the return key
End If
End Function
Edit: KeyDown probably not a good name for the function so I renamed it KeyDownTest but I get the same error
Last edited: