Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help sending data to clipboard with windows API

Status
Not open for further replies.

Sorwen

Technical User
Joined
Nov 30, 2002
Messages
1,641
Location
US
I'm trying to set data directly to the clipboard so it can then be pasted in another program. For a test I get the current date and if it isn't xx/xx/xxxx I add zeroes where needed. Example today would be 7/21/2005 and I want 07/21/2005. I then want to send it to the clipboard, but it doesn't work.

' Code ----------------------------------------------------
Option Compare Database
Public Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function CloseClipboard Lib "user32" () As Long
Public Declare Function EmptyClipboard Lib "user32" () As Long
Public Declare Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As Long) As Long

Option Explicit

Function MyModifiedDate()

Dim CurrentDate As String
Dim Slash1 As Integer, Slash2 As Integer
Dim MyMonth As String, MyDay As String, MyYear As String
Dim EndCurrentDate As String
Const CF_DSPTEXT = 8

CurrentDate = Date
Slash1 = InStr(1, CurrentDate, "/")
Slash2 = InStr((Slash1 + 1), CurrentDate, "/")

'Calculate Month
If (Len(Left(CurrentDate, Slash1 - 1)) = 1) Then
MyMonth = "0" & Left(CurrentDate, Slash1 - 1)
Else
MyMonth = Left(CurrentDate, Slash1 - 1)
End If

'Calculate Day
If (Len(Mid(CurrentDate, Slash1 + 1, ((Slash2 - Slash1) - 1))) = 1) Then
MyDay = "0" & Left(CurrentDate, Slash1 - 1)
Else
MyDay = Mid(CurrentDate, Slash1 + 1, ((Slash2 - Slash1) - 1))
End If

'Calculate Year
MyYear = Mid(CurrentDate, Slash2 + 1, ((Len(CurrentDate) - Slash2) - 1))

EndCurrentDate = MyMonth & MyDay & MyYear

OpenClipboard hWndAccessApp
EmptyClipboard
SetClipboardData CF_DSPTEXT, EndCurrentDate
CloseClipboard

End Function
' End Code -----------------------------------------------



Can anyone help me with why this doesn't set the data to the clipboard? It is totally empty.

Thank you,
Sorwen
 
For the ClipBoard I don't know, but for the date why not simply this ?
EndCurrentDate = Format(Date, "mmddyyyy")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Later I will have to manipulate the date more as our system doesn't use a standard date format, but that Format() will help cut out the steps that add the 0. Didn't know about it. Thanks.
 
Don't know much about the clipboard API's neither, but if you copy the date to a form text control, then you can do

[tt]me!txtControl.setfocus
docmd.runcommand accmdcopy[/tt]

- then it should be available (this is, if using the default setting where the whole control is selected)

Roy-Vidar
 
It doesn't run in a form. I could do it that way, but because I don't need the form I want to avoid it. Thanks though.

PHV - I could hurt myself for not looking for something like that. I can do all of my needed changes directly in Format.
 
Here's a thread with some more API stuff, too, thread705-593376

Roy-Vidar
 
It looks like that should help. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top