autokey shortcut insert an incrementing number (1 Viewer)

peskywinnets

Registered User.
Local time
Today, 15:35
Joined
Feb 4, 2014
Messages
576
I seek a way of selecting a table field, then having a preset autokey (shortcut key) configured, that when pressed, runs a bit of VBA, that inserts a number (1 more than the last) into the selected field.

I know how to do autokeys.

I know how to store a number, recall it, increment it, then store it away again.

What I don't know is the mechanism of getting that number out of the VBA code (a variable)& into the clipboard.

A bit of googling revealed this...

https://www.access-programmers.co.uk/forums/showthread.php?t=224088

specifically, this post...
___________________________________________

I have now got it workiny by using the following.
Quote:
Dim DataObj As New MSForms.DataObject
Dim S As String
S = Me.Stores_Address
DataObj.SetText S
DataObj.PutInClipboard
It didn't work earlier as FM20.dll was not referenced in tools / reference. As soon as I manually referenced this, it all started to work.

___________________________________________

...it's not working for me either...presumably I need to enable FM20.dll ...but I don't see it under references?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:35
Joined
Oct 29, 2018
Messages
21,358
Hi. See if you can use TempVars.
 

peskywinnets

Registered User.
Local time
Today, 15:35
Joined
Feb 4, 2014
Messages
576
Thanks...I googled tempvars, but there's a whole lot of learning for me there!

I've just managed to sort it ...all I had to do was use the 'Browse' option in references, to locate FM20.dll in windows/system32

Once done, this code works...

Code:
Dim obj As New DataObject
Dim txt As String

'Put some text inside a string variable
  txt = "This was copied to the clipboard using VBA!"

'Make object's text equal above string variable
  obj.SetText txt

'Place DataObject's text into the Clipboard
  obj.PutInClipboard

'Notify User
  MsgBox "There is now text copied to your clipboard!", vbInformation

original reference - https://www.thespreadsheetguru.com/blog/2015/1/13/how-to-use-vba-code-to-copy-text-to-the-clipboard
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:35
Joined
Oct 29, 2018
Messages
21,358
Thanks...I googled tempvars, but there's a whole lot of learning for me there!

I've just managed to sort it ...all I had to do was use the 'Browse' option in references, to locate FM20.dll in windows/system32

Once done, this code works...

Code:
Dim obj As New DataObject
Dim txt As String

'Put some text inside a string variable
  txt = "This was copied to the clipboard using VBA!"

'Make object's text equal above string variable
  obj.SetText txt

'Place DataObject's text into the Clipboard
  obj.PutInClipboard

'Notify User
  MsgBox "There is now text copied to your clipboard!", vbInformation
original reference - https://www.thespreadsheetguru.com/blog/2015/1/13/how-to-use-vba-code-to-copy-text-to-the-clipboard
Hi. Glad to hear you got it sorted out. Good luck with your project.
 

Users who are viewing this thread

Top Bottom