Screenshot of Wrong Form (1 Viewer)

Cat_129

Registered User.
Local time
Today, 23:55
Joined
Sep 18, 2019
Messages
36
Hey, me again....

Today's problem is as follows

I have a data entry form with an approval button on it, someone clicks the button, it puts their name and time of clicking into a box, takes a screenshot an emails it to certain people. Works brilliantly

What I have next, is a continuous form, that behaves like a log for all of the data entry forms generated. This also has the approval button on it, exact same purpose, but negates the need to open the data entry form to approve. The approval on the log form needs to open the data entry form, click the approved button, take a screenshot of the data entry form with the approval box filled, email this and then close itself.

I have this almost completely working. When it comes to taking the screenshot, it takes a screenshot of the log form (the one the clicked button is on) not of the data entry form which is what I need.

I am assuming this is because the code is running on the log form, not the data entry form, is there a way around this?

Thanks,
Cat
 

isladogs

MVP / VIP
Local time
Today, 23:55
Joined
Jan 14, 2017
Messages
18,246
Depends on the code used. Try setting focus to the required form before you take a screen shot or modify your code in a similar way to this

Code:
Dim frm As Access.Form
Set frm = "YourDataEntryFormName

PrintscreenForm frm

where PrintScreenForm is the name of your function used to take the screenshot
 

Cat_129

Registered User.
Local time
Today, 23:55
Joined
Sep 18, 2019
Messages
36
Depends on the code used. Try setting focus to the required form before you take a screen shot or modify your code in a similar way to this

Code:
Dim frm As Access.Form
Set frm = "YourDataEntryFormName

PrintscreenForm frm

where PrintScreenForm is the name of your function used to take the screenshot

Worked great thank you, just had to tweak it to be Forms.FormName
 

Cat_129

Registered User.
Local time
Today, 23:55
Joined
Sep 18, 2019
Messages
36
Depends on the code used. Try setting focus to the required form before you take a screen shot or modify your code in a similar way to this

Code:
Dim frm As Access.Form
Set frm = "YourDataEntryFormName

PrintscreenForm frm

where PrintScreenForm is the name of your function used to take the screenshot

I Lied....Sorry, I was accidentally running the wrong macro when I tested it :banghead: any further ideas? Thanks for all the help recently, I should pay you all a retainer...
 

isladogs

MVP / VIP
Local time
Today, 23:55
Joined
Jan 14, 2017
Messages
18,246
I Lied....Sorry, I was accidentally running the wrong macro when I tested it :banghead: any further ideas? Thanks for all the help recently, I should pay you all a retainer...

Feel free to do so :D
Anyway your response is unclear. Does the screenshot code work at all?
Anyway like most of the developers here, I don't use macros....
 

Cat_129

Registered User.
Local time
Today, 23:55
Joined
Sep 18, 2019
Messages
36
So this uses a code that arnelgp gave me to create the screenshot. (https://www.access-programmers.co.uk/forums/showthread.php?t=306902)

Then the rest goes as follows

This is run from the log form
Code:
DoCmd.OpenForm "Deviations", , , "[DR Number] = " & Me![DR Number]

Call BTNLeadApproval_Click

this is running in the data entry form
Code:
Public Sub BTNLeadApproval_Click()

Forms.Deviations.Department_Approval__Lead_Engineer_.Value = (Environ$("Username")) & " - " & (Now())

Call MDIClientToBMP(Environ("userprofile") & "\documents\myScreenPic.bmp")
        
Dim oApp As Object
Dim oMail As Object

Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(0)

With oMail
    .BodyFormat = 3
    .To = 
    .Subject = "Deviation " & Forms.Deviations.DR_Number & " Approved - Lead Engineer " & Forms.Deviations.Department_Approval__Lead_Engineer_
    .Attachments.Add Environ("userprofile") & "\documents\myScreenPic.bmp"
    .HTMLBody = "<p><img src='cid:myScreenPic.bmp'>
    .Send

DoCmd.Close ObjectType:=acForm, objectname:="Deviations", Save:=acSaveYes

    MsgBox "Approval Form Emailed"
End With

End Sub

The part where it's calling
Code:
 Call MDIClientToBMP(Environ("userprofile") & "\documents\myScreenPic.bmp")
is where it's not behaving as expected

P.S. Is there a difference between code and a macro? I always assumed they were the same thing, in that a macro ran code
 

isladogs

MVP / VIP
Local time
Today, 23:55
Joined
Jan 14, 2017
Messages
18,246
Perhaps you should have made that clear from the start....;)
The module code with the MDIClientToBMP function will need adapting to grab the hWnd of the form you want to capture.
As you're using arnel's code, its better he answers the question in detail
I expect he'll be around soon to do so
 

Cat_129

Registered User.
Local time
Today, 23:55
Joined
Sep 18, 2019
Messages
36
Thank You, I am now leaving work for the weekend so won't have access to this until Monday, all help is really appreciated.
 

Cat_129

Registered User.
Local time
Today, 23:55
Joined
Sep 18, 2019
Messages
36
Just wanted to let you know that I have solved this,

I just changed the order things were done in, so I had the message box pop up on the second form which then made the screen capture happen on the second form.

Thanks for all your help

Cat
 

Users who are viewing this thread

Top Bottom