Take Picture from Laptop Webcamera (1 Viewer)

dgreen

Member
Local time
Today, 17:28
Joined
Sep 30, 2018
Messages
397
Does anyone have experience with 1) showing the person's image live, on the Access form, before the picture (so they can center themselves beforehand, look into the camera, etc...), then 2) taking the picture and storing the result in a designated location?

Code:
Private Sub btnTakePicture_Click()
'https://social.msdn.microsoft.com/Forums/en-US/1e9eebcb-5abe-404d-882b-5cb302b771e4/wia-taking-a-picture-from-webcam?forum=isvvba
'Take a picture from a webcam and store it in a temp file.
'By Justin Johnson Nov 26, 2007
'Add to VBA References: Microsoft Windows Image Acquisition Library v2.0
 
On Error GoTo Err_btnTakePicture_click
 
Dim tempfile As String
Dim mydevice As WIA.Device
Dim item As WIA.item
Dim imfile As WIA.imagefile
Dim Commondialog1 As WIA.CommonDialog
 
'put the path and name for the location of your temp file here.
tempfile = ("http://sharepoint/Contacts/filename.jpg")
 
'the next 4 lines deletes the old temp file if it exists
Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
If FileSystemObject.FileExists(tempfile) Then
    Kill (tempfile)
End If
 
'the next two lines set up the configuration
Set Commondialog1 = New CommonDialog
Set mydevice = Commondialog1.ShowSelectDevice
 
Set item = mydevice.ExecuteCommand(wiaCommandTakePicture) 'instructs the camera to take the picture
Set imfile = item.Transfer 'transfers the picture from the camera
 
'this line saves the picture to a specified file
imfile.SaveFile (tempfile)
'this sets the picture on the form to show the new picture
Me.OLEUnbound1.Picture = (tempfile)
MsgBox "Picture taken"
Exit_btnTakePicture_click:
    Set mydevice = Nothing
    Set item = Nothing
    Exit Sub
Err_btnTakePicture_click:
    MsgBox Err.Description, vbOKOnly + vbCritical, "Error Taking Picture"
    Resume Exit_btnTakePicture_click
End Sub
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 23:28
Joined
Jul 9, 2003
Messages
16,273
I Noticed that you have yet to receive a reply. Hence I'm bumping your post up the list so that it gets a second look... I would suggest you do a vigorous search of the forum because this question pops up reasonably frequently. I think there's some proprietary software you can buy...

The new search facility provided with this forum is excellent, (Button Top Right) however you can also use Google see this post:- https://www.niftyaccess.com/searching-for-answers/

And press on the button marked "search access world forums only"
 

dgreen

Member
Local time
Today, 17:28
Joined
Sep 30, 2018
Messages
397
Database from https://www.access-programmers.co.uk/forums/threads/cheap-alternative-to-access-imagine.307217/

I was able to take my first picture without issues. Downloaded the zip file, extracted it, added a notional studentID, clicked Take Photo, smiled and clicked Take a snapshot and the image saved in the StudentPictures folder that was created in the same directory as the file.

Issue: I wanted to add another user and now the "Take a snapshot" is greyed out. I want to change my picture and again the "Take a snapshot" is greyed out. Can't click to get an error message.

Visual below shows that I have provided the studentID, gotten the webcamera up, it's showing my face, the folder where the picture is to be stored exists.
Picture1.png


Here's the code behind the cmdSnapshot.
Code:
Private Sub cmdSnapshot_Click()
    Dim sFile As String
    sFile = Eval(DLookup("Expression", "tblCommon", "Entity = 'PathToPicture'"))
    If SysCmd(acSysCmdGetObjectState, acForm, "frmPhoto") <> 0 Then
        If Trim(Forms("frmPhoto")!StudentID & "") <> "" Then
            Call fnkMakeFolder(sFile)
            sFile = sFile & Forms("frmPhoto")!StudentID & ".bmp"
            SendMessage Hcamera, WM_CAP_FILE_SAVEDIB, 0&, ByVal (sFile)
            Forms("frmPhoto")!PictureFile = sFile
            Forms("frmPhoto").Form.Dirty = False
            Forms("frmPhoto")!Image1.Requery
        End If
    Else
        sFile = Environ("userprofile") & "\Desktop\Capture.bmp"
        SendMessage Hcamera, WM_CAP_FILE_SAVEDIB, 0&, ByVal (sFile)
    End If
   
End Sub
]

What am I missing?

I came across this posting that is a great start for me. I'll need to modify it but it's a great start.
https://www.access-programmers.co.uk/forums/threads/cheap-alternative-to-access-imagine.307217/
 

Users who are viewing this thread

Top Bottom