M
Matthew Pfluger
Hello all,
I've got a curious case. When I step through the following code, it works
just fine. When I let it run by itself, it throws the error 2046 - The
command or action 'Copy' isn't available now.
Here's the code:
===============================================
' Get screen information
Dim alngTwipsPerPixel(0 To 1) As Long
GetTwipsPerPixel alngTwipsPerPixel(0), alngTwipsPerPixel(1) ' returns 15,15
' Move mouse cursor to "Select All Records" button at top left corner of
datasheet
MoveMouse 25, frmSource.FormHeader.Height / alngTwipsPerPixel(0) + 25
' Send a command to left click the mouse
LeftMouseClick
' Copy all records, formatting, and captions to the Clipboard
DoCmd.RunCommand acCmdCopy ' code will fail here when running w/o
breakpoint
===============================================
The code is designed to click on the "Select All Records" button on the
datasheet portion of a Split Form (see my post "Use VBA to switch view in
Split Form" from yesterday) and copy all records to the Clipboard for pasting
into Excel. The reason I do this instead of accessing the Form's recordset
is that through this method you copy all formatting and field captions in
addition to displayed data.
Can anyone tell me why the code works when stepping through, but it fails
when running without debugging? Thank you for your help.
Matthew Pfluger
I've got a curious case. When I step through the following code, it works
just fine. When I let it run by itself, it throws the error 2046 - The
command or action 'Copy' isn't available now.
Here's the code:
===============================================
' Get screen information
Dim alngTwipsPerPixel(0 To 1) As Long
GetTwipsPerPixel alngTwipsPerPixel(0), alngTwipsPerPixel(1) ' returns 15,15
' Move mouse cursor to "Select All Records" button at top left corner of
datasheet
MoveMouse 25, frmSource.FormHeader.Height / alngTwipsPerPixel(0) + 25
' Send a command to left click the mouse
LeftMouseClick
' Copy all records, formatting, and captions to the Clipboard
DoCmd.RunCommand acCmdCopy ' code will fail here when running w/o
breakpoint
===============================================
The code is designed to click on the "Select All Records" button on the
datasheet portion of a Split Form (see my post "Use VBA to switch view in
Split Form" from yesterday) and copy all records to the Clipboard for pasting
into Excel. The reason I do this instead of accessing the Form's recordset
is that through this method you copy all formatting and field captions in
addition to displayed data.
Can anyone tell me why the code works when stepping through, but it fails
when running without debugging? Thank you for your help.
Matthew Pfluger