Results 1 to 9 of 9
  1. #1
    ahmedbasheer is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Dec 2017
    Posts
    8

    insert the picture employ in column all picture using command

    hello
    i have folder include the picture employ, the name of the pictures is a number of employ
    and i have database include table1 the column in table (emp_id as number ,emp_name as text, emp_picture as attachment )

    i need insert all picture in table1 column emp_picture using command when the name of picture = number in emp_id



    note

    i have more than 1000 record and 1000 picture

    thank you

    i attach the example to modify
    Attached Files Attached Files

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,515
    do you want to:
    embed the image into the record permenantly into an OLE field (takes up space)?
    or
    insert the text of the path to the image (to save space, like: c:\folder\folder\1234.jpg) then load the image on demand in a form?

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,795
    Requires VBA code. Here is one tutorial http://sourcedaddy.com/ms-access/wor...nt-fields.html

    Code adapted for your situation:
    Code:
    Public Sub LoadAttachments()
        Dim dbs As DAO.Database
        Dim rst As DAO.Recordset2
        Dim rsA As DAO.Recordset2
        Dim fld As DAO.Field2
        Dim strFile As String
        Set dbs = CurrentDb
        Set rst = dbs.OpenRecordset("tabl1")
        Set fld = rst("emp_picture")
        
        Do While Not rst.EOF
            Set rsA = fld.Value
            strFile = "your folder path\" & rst!emp_id & ".jpg"
            rst.Edit
            If Dir(strFile) <> "" Then
                rsA.AddNew
                rsA("FileData").LoadFromFile strFile
                rsA.Update
            End If
            rsA.Close
            rst.Update
            rst.MoveNext
        Loop
        rst.Close
        dbs.Close
        Set fld = Nothing
        Set rsA = Nothing
        Set rst = Nothing
        Set dbs = Nothing
    End Sub
    Keep in mind that embedded files can really chew up Access 2GB file size limit, however, if all the images are this small, might not be a issue.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    ahmedbasheer is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Dec 2017
    Posts
    8
    Thank you for all
    Mr ranman256 I need embed the image into the record

    Mr june7 I will use this cood and I tell you about the result

  5. #5
    ahmedbasheer is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Dec 2017
    Posts
    8
    hello
    i try it but don't working
    you an see the example attachment
    Attached Files Attached Files

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,795
    "Don't work" means what - error message, wrong results, nothing happens?

    The file has no VBA at all. There is no attempt at using the code.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    ahmedbasheer is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Dec 2017
    Posts
    8
    thank you for reply
    i try the code you suggest put example nothing happens

    I am sorry because attach the wrong file

    Attached Files Attached Files

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,795
    Need a backslash as shown below in red:

    strFile = "C:\Users\basma\Downloads\database and folder\New folder\emp_pic\" & rst!emp_id & ".jpg"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    ahmedbasheer is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Dec 2017
    Posts
    8
    thank you for all
    after editing code the program start successful

    thank you

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

Similar Threads

  1. Changing Picture on Command Button
    By kdbailey in forum Access
    Replies: 9
    Last Post: 03-30-2017, 06:24 PM
  2. Insert picture in access form
    By josnghi in forum Forms
    Replies: 4
    Last Post: 01-15-2016, 03:34 PM
  3. Picture insert problem
    By allstar45 in forum Reports
    Replies: 3
    Last Post: 04-20-2012, 01:17 PM
  4. Insert a picture with macro
    By KWarzala in forum Forms
    Replies: 8
    Last Post: 09-23-2009, 08:43 AM
  5. Avoid jump to first data after insert new picture
    By gigolomoden in forum Programming
    Replies: 0
    Last Post: 08-04-2008, 10:08 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