I am writing a VBA program in access that opens a JD Edwards window pulls data to insert into a table, printscreen and save to a file, and then moves on to the next window. Everything is working, however, the only way I could find to copy the window is use keybd_event. When I initially ran this the clipboard was empty, I finally figured out that the code was moving forward before the printscreen was complete so I put a short timer in. My problem with this timer is that it isn't fool proof. If the computer is bogged down with background tasks it can take longer than the 2 seconds I have in the code. On the other hand I am running through hundreds of screens so I want this timer to be a small as possible. Does anyone have a better way of verifying that the print screen is complete before allowing the code to move forward?
Below is the code to clear the clipboard, copy the window to the clipboard, and the timer.
Below is the code to clear the clipboard, copy the window to the clipboard, and the timer.
Code:
'Clear Clipboard
If OpenClipboard(0&) <> 0 Then
Call EmptyClipboard
Call CloseClipboard
End If
'Copy Window
osinfo.dwOSVersionInfoSize = 148
osinfo.szCSDVersion = Space$(128)
retvalue = GetVersionExA(osinfo)
If osinfo.dwMajorVersion > 4 Then
blnAboveVer4 = True
Else
blnAboveVer4 = False
End If
If blnAboveVer4 Then
keybd_event VK_SNAPSHOT, 1, 0, 0
Else
keybd_event VK_MENU, 0, 0, 0
keybd_event VK_SNAPSHOT, 0, 0, 0
keybd_event VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0
keybd_event VK_MENU, 0, KEYEVENTF_KEYUP, 0
End If
'Give keybd_event time to fill clipboard
Wait = Now + TimeValue("00:00:02")
Do
DoEvents
Loop Until Now >= Wait