Page 1 of 3 123 LastLast
Results 1 to 15 of 38
  1. #1
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Paste Clipboard to Blank Report using code (A2K SR1)

    Report1 is a blank report. How can you copy the contents of the clipboard to the detail section of the report when in design mode using code. I have been trying the acCmdPaste run command on the on open event of the report but can't set focus to the detail section of the report in design mode using code.
    Regards,

    Gary
    (It's been a while!)

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Paste Clipboard to Blank Report using code (A2K SR1)

    You use API calls to manipulate the clipboard from code. There's code in the Access Developer's Handbooks, among other places, that wraps this up in functions for you.

    What exactly are you trying to do? You can easily use code to examine a control on one object (say a form or report) and use the CreateControl method to duplicate the control on another object without any copy and paste.
    Charlotte

  3. #3
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Paste Clipboard to Blank Report using code (A2K SR1)

    You said, <What exactly are you trying to do?>

    Since I can't save a form directly to a Snapshot, I was looking for a work around. I already have the ability to take screen shots of any form and save them to the clipboard. I figured that I should then be able to paste the clipboard image into a report that could then be saved as a snapshot.

    I know I could just create reports to do this but it isn't as much fun.... <img src=/S/dizzy.gif border=0 alt=dizzy width=15 height=15>
    Regards,

    Gary
    (It's been a while!)

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Paste Clipboard to Blank Report using code (A2K SR1)

    OK, now I know what you're trying to do. But what are you trying to DO ... and why?
    Charlotte

  5. #5
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Paste Clipboard to Blank Report using code (A2K SR1)

    Basically, the users of the database have requested that they have the ability to create an electronic copy of any form. (I did this by giving them the ability to save a screen shot of the form to the clipboard by pressing a command button. They were too lazy to press Alt Printscreen. <img src=/S/weep.gif border=0 alt=weep width=21 height=16> )

    Of course, the database has many forms. The users now said, could you now create a way to print out all of the forms associated with a project by selecting the project from a pull down menu. (I did this as well. <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23> - After selecting a project a command button launches all of the associated forms and prints them )

    Now the users said this is all neat, however, we want to be able to select a project and save all of the forms in electronic format. Thus, my dilemma <img src=/S/bummer.gif border=0 alt=bummer width=15 height=15> - I want to save the forms as electronic copies (i.e, snapshot) without creating additional reports to do this. (I am lazy.... <img src=/S/snore.gif border=0 alt=snore width=32 height=15> and don't want to create a report associated with every form.)

    That's it in a nut shell.... <img src=/S/scratch.gif border=0 alt=scratch width=25 height=29> - any ideas??
    Regards,

    Gary
    (It's been a while!)

  6. #6
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Paste Clipboard to Blank Report using code (A2K SR1)

    As you've already got the form onto the clipboard, you could automate Word and create a document with all the relevant screen shots in it?
    Regards,
    Rory

    Microsoft MVP - Excel

  7. #7
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Paste Clipboard to Blank Report using code (A2K SR1)

    Thanks Rory,

    I was already leaning in this direction since it appears creating the snapshot files of the forms is more of a headache <img src=/S/bash.gif border=0 alt=bash width=35 height=39> then its worth. Also - In word, I could insert all of the forms in one document (one neat package) as opposed to creating twenty or so snapshot files.

    Thanks for the idea.
    Regards,

    Gary
    (It's been a while!)

  8. #8
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Paste Clipboard to Blank Report using code (A2K SR1)

    ... This appears easier seen then done....

    I can take a screen print of the file, however, sometimes it pastes into word and sometimes it doesnt. The code is below, and suggestions on why this is inconsistent?

    Dim stForm As String 'Name of Report Form
    Dim stDocName As String ' Name of form to open
    Dim stLinkCriteria As String

    DoCmd.SetWarnings off

    'Set stForm to Form where Clin Slin is selected
    stForm = "FORM - Program Report"
    ' Set C = to the Clin Slin Selected for use with other forms
    C = Me.SelectClinSlin.Column(0)
    DoCmd.Close

    'FORM DASHBOARD - BY CLIN
    ' Open Dashboard Form for first file
    stDocName = "DASHBOARD - BY CLIN"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    ' Set ClinSlin selection to C
    Forms(stDocName)!SelectClinSlin.Value = C

    ' Create ScreenShot of Form to Clipboard
    ScreenDump

    ' Start Word to paste screen shots into
    Dim wordapp As Word.Application
    Set wordapp = CreateObject("Word.Application")
    wordapp.Visible = True

    With wordapp
    .Documents.Add Template:="", NewTemplate:=False, DocumentType:=0
    .Selection.Paste
    .ScreenRefresh
    End With
    wordapp.ActiveDocument.SaveAs "C:aaatest.doc"
    wordapp.ActiveDocument.Close

    Set wordapp = Nothing

    ' Close Form
    DoCmd.Close
    Regards,

    Gary
    (It's been a while!)

  9. #9
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Paste Clipboard to Blank Report using code (A2K SR1)

    One last clarification, in the last response I indicated that sometimes the paste doesn't work. What I meant is sometime the paste inserts the correct screenshot based on the parameters selected, and sometimes is pastes the default value driving the form which is not what I intended.
    Regards,

    Gary
    (It's been a while!)

  10. #10
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Paste Clipboard to Blank Report using code (A2K SR1)

    I'm curious what's behind this. Is the user asking for documentation of the database, or are they wanting to make archival copies of reports they send out to the world? If it's the former, as soon as somebody makes a design change, the documentation is out of date. I keep trying to convince our users that the database is self-documenting, though many are not convinced. If it's the latter, it sounds like what they real need is some sort of COLD system that provides an electronic copy of a paper document produced and sent out to someone. That's a problem that has solutions although they tend to be expensive.
    Wendell

  11. #11
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Paste Clipboard to Blank Report using code (A2K SR1)

    Are you doing any other copying at any point (manual or via code)?
    Can you post your code for the screendump routine?
    Regards,
    Rory

    Microsoft MVP - Excel

  12. #12
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Paste Clipboard to Blank Report using code (A2K SR1)

    ... What's behind this is...
    The users are not asking for documentation of the database or archival copies of reports. The database is a supplemental Program Management tool that tracks and groups various data from different systems (i.e., MPM, MS Project, Accounting, Finance....) Each screen enables the user to review a different set of data related to a program. What the users want is the ability to create an electronic copy of all of the forms associated with a particular program so they can review it without having to remember how to navigate between all of the screens.
    Regards,

    Gary
    (It's been a while!)

  13. #13
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Paste Clipboard to Blank Report using code (A2K SR1)

    You said
    <Are you doing any other copying at any point (manual or via code)?>
    - No, I am not doing any other copying at any point whether manually or by code.

    The code for the screendump routine was obtained from "The Access Web". It is saved as a function and called via code. After the user selects a project from a combobox on a form, the user presses a command button to launch the sequence to open a form(s), set a parameter on the form that updates the form data based on the combo box selection made, take a screen shot of the form and pass the screen shot to Word.

    The code to capture the screen shot is below:

    Option Compare Database
    Option Explicit

    Type RECT_Type

    left As Long
    top As Long
    right As Long
    bottom As Long

    End Type

    'The following declare statements are case sensitive.

    Declare Function GetActiveWindow Lib "User32" () As Long
    Declare Function GetDesktopWindow Lib "User32" () As Long
    Declare Sub GetWindowRect Lib "User32" (ByVal Hwnd As Long, _
    lpRect As RECT_Type)
    Declare Function GetDC Lib "User32" (ByVal Hwnd As Long) As Long
    Declare Function CreateCompatibleDC Lib "Gdi32" (ByVal hdc As Long) _
    As Long
    Declare Function CreateCompatibleBitmap Lib "Gdi32" (ByVal hdc _
    As Long, ByVal nWidth As Long, _
    ByVal nHeight As Long) As Long
    Declare Function SelectObject Lib "Gdi32" (ByVal hdc As Long, _
    ByVal hObject As Long) As Long
    Declare Function BitBlt Lib "Gdi32" (ByVal hDestDC As Long, _
    ByVal X As Long, ByVal Y _
    As Long, ByVal nWidth As Long, _
    ByVal nHeight As Long, _
    ByVal hSrcDC As Long, _
    ByVal XSrc As Long, _
    ByVal YSrc As Long, _
    ByVal dwRop As Long) As Long
    Declare Function OpenClipboard Lib "User32" (ByVal Hwnd As Long) As Long
    Declare Function EmptyClipboard Lib "User32" () As Long
    Declare Function SetClipboardData Lib "User32" (ByVal wFormat As Long, _
    ByVal hMem As Long) As Long
    Declare Function CloseClipboard Lib "User32" () As Long
    Declare Function ReleaseDC Lib "User32" (ByVal Hwnd As Long, _
    ByVal hdc As Long) As Long
    Declare Function DeleteDC Lib "Gdi32" (ByVal hdc As Long) As Long

    Global Const SRCCOPY = &HCC0020
    Global Const CF_BITMAP = 2

    Function ScreenDump()
    Dim AccessHwnd As Long, DeskHwnd As Long
    Dim hdc As Long
    Dim hdcMem As Long
    Dim rect As RECT_Type
    Dim junk As Long
    Dim fwidth As Long, fheight As Long
    Dim hBitmap As Long

    DoCmd.Hourglass True

    '---------------------------------------------------
    ' Get window handle to Windows and Microsoft Access
    '---------------------------------------------------
    DeskHwnd = GetDesktopWindow()
    'DeskHwnd = GetActiveWindow()
    AccessHwnd = GetActiveWindow()

    '---------------------------------------------------
    ' Get screen coordinates of Microsoft Access
    '---------------------------------------------------
    Call GetWindowRect(AccessHwnd, rect)
    fwidth = rect.right - rect.left
    fheight = rect.bottom - rect.top

    '---------------------------------------------------
    ' Get the device context of Desktop and allocate memory
    '---------------------------------------------------
    hdc = GetDC(DeskHwnd)
    'hdc = GetDC(AccessHwnd)
    hdcMem = CreateCompatibleDC(hdc)
    hBitmap = CreateCompatibleBitmap(hdc, fwidth, fheight)

    If hBitmap <> 0 Then
    junk = SelectObject(hdcMem, hBitmap)

    '---------------------------------------------
    ' Copy the Desktop bitmap to memory location
    ' based on Microsoft Access coordinates.
    '---------------------------------------------
    junk = BitBlt(hdcMem, 0, 0, fwidth, fheight, hdc, rect.left, _
    rect.top, SRCCOPY)

    '---------------------------------------------
    ' Set up the Clipboard and copy bitmap
    '---------------------------------------------
    junk = OpenClipboard(DeskHwnd)
    junk = EmptyClipboard()
    junk = SetClipboardData(CF_BITMAP, hBitmap)
    junk = CloseClipboard()
    End If

    '---------------------------------------------
    ' Clean up handles
    '---------------------------------------------
    junk = DeleteDC(hdcMem)
    junk = ReleaseDC(DeskHwnd, hdc)

    DoCmd.Hourglass False

    End Function
    Regards,

    Gary
    (It's been a while!)

  14. #14
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Paste Clipboard to Blank Report using code (A2K SR1)

    Hi Gary,
    I'd suggest modifying your screendump function so that it uses the form's Hwnd property to get the form handle rather than using GetActiveWindow and see if that helps.
    i.e. change it to:
    <pre>Function ScreenDump(frm as Form)
    Dim AccessHwnd As Long, DeskHwnd As Long
    Dim hdc As Long
    Dim hdcMem As Long
    Dim rect As RECT_Type
    Dim junk As Long
    Dim fwidth As Long, fheight As Long
    Dim hBitmap As Long

    DoCmd.Hourglass True

    '---------------------------------------------------
    ' Get window handle to Windows and Microsoft Access
    '---------------------------------------------------
    DeskHwnd = GetDesktopWindow()
    'DeskHwnd = GetActiveWindow()
    AccessHwnd = frm.Hwnd
    etc....
    </pre>

    and simply pass the relevant form as an argument each time you call the function.
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  15. #15
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Paste Clipboard to Blank Report using code (A2K SR1)

    Thanks Rory,

    I will give this a try and let you know how it worked. <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    Regards,

    Gary
    (It's been a while!)

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •