Results 1 to 8 of 8
  1. #1
    robjones01 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    8

    Image transfer with WIA

    I'm struggling with getting some code to take a picture and transfer the image to the PC and save the file.

    It works up to line Set imfile = item.Transfer 'transfers the picture from the camera and then produces an error stating

    "Object Variable or With Block variable not set"



    I'm completely lost, it's working great and taking the picture but I'm just not able to then transfer the image

    Code:
    Option Compare Database
    Dim objDeviceInfo As WIA.DeviceInfo
    Dim objDevice As WIA.Device
    Dim objDeviceManager As WIA.DeviceManager
    Dim objItem As WIA.item
    Dim objImage As WIA.ImageFile
    Dim intCount, intLoop As Integer
    Dim objFSO As Scripting.FileSystemObject
    Dim strTempPicture As String
    
    Private Sub cmdTakePicture_Click()
     
        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
        Dim MyFilename As String
     
        MyFilename = DLookup("[Pic_Location]", "sysProperties") & Forms![frmMembers_Details]![MemberNumber] & ".jpg"
     
        'put the path and name for the location of your temp file here.
        tempfile = (MyFilename)
     
        '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.imgPicture.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

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    you defined it 1 way:
    Dim Commondialog1 As WIA.CommonDialog

    then set it another:
    Set Commondialog1 = New CommonDialog

    shouldnt it be the same?

  3. #3
    robjones01 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    8
    Don't think so, that element works OK. It takes the picture and then files at the Image Transfer

    Quote Originally Posted by ranman256 View Post
    you defined it 1 way:
    Dim Commondialog1 As WIA.CommonDialog

    then set it another:
    Set Commondialog1 = New CommonDialog

    shouldnt it be the same?

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    This is not addressed at your specific issue, but you should also have Option Explicit at the top/ of each module.
    This will identify any undeclared variables.

    What exactly does this mean?
    I'm completely lost, it's working great and taking the picture but I'm just not able to then transfer the image
    You have been using this successfully?
    You have never been able to transfer the image?

    I do not use WIA, but have used a routine by Emilio to resize images that may be helpful re syntax etc.
    Last edited by orange; 01-26-2018 at 08:36 AM. Reason: added link to WIA sample

  5. #5
    robjones01 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    8
    Apologies, I'd missed the Option Explicit...

    The code works to take the picture and stores it on the camera but I can't then get the WIA Transfer to move the image to the PC to save.


    Quote Originally Posted by orange View Post
    This is not addressed at your specific issue, but you should also have Option Explicit at the top/ of each module.
    This will identify any undeclared variables.

    What exactly does this mean?


    You have been using this successfully?
    You have never been able to transfer the image?

    I do not use WIA, but have used a routine by Emilio to resize images that may be helpful re syntax etc.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    Is this a separate camera or a camera built in to your laptop etc?

    Has the transfer ever worked OR are you trying to use code you found?
    If it's code you found, can you show us where you got it --perhaps there's more to the code/article than you are showing.

  7. #7
    robjones01 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    8
    It's code I found and its using a seperate camera.

    I can't remember where I found the code as I've been trying to do it for weeks, I can only seem to do it if I use the ShowAcquireImage function of WIA to select the picture and then save it.
    I think the problem is that it's unable to pull the filename off the camera to save it

    Quote Originally Posted by orange View Post
    Is this a separate camera or a camera built in to your laptop etc?

    Has the transfer ever worked OR are you trying to use code you found?
    If it's code you found, can you show us where you got it --perhaps there's more to the code/article than you are showing.

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    Is this a separate camera or a camera built in to your laptop etc?

    I found the code here
    https://bytes.com/topic/access/answe...re-windows-7-a

    It also says Works great in Windows XP but fails in W7 with an error stating: "object variable or with block variable not set". The camera does open up and flash so it appears to take the picture but no result in image frame.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 12-26-2016, 08:57 AM
  2. Export image as image
    By gumbi17 in forum SQL Server
    Replies: 3
    Last Post: 08-15-2016, 09:17 PM
  3. Replies: 3
    Last Post: 07-13-2015, 12:07 PM
  4. Replies: 2
    Last Post: 10-10-2011, 10:58 AM
  5. Transfer Data from Old DB to New
    By 1eye1vision in forum Import/Export Data
    Replies: 7
    Last Post: 08-06-2011, 02:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums