Results 1 to 9 of 9
  1. #1
    Baz16 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2015
    Posts
    11

    Exporting Attachments from a UserForm to Access Table

    Hi, I have an excel document with a few userforms.



    When you press a command button it exports all the data from the text boxes into an access db table.
    Is there a way to export attachments in a similar way.

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Access attachements are spreadsheets, do you mean ...
    take the current worksheet and click SAVE AS ,
    to save the worksheet to the name of the workbook currently attached in Access?

  3. #3
    Baz16 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2015
    Posts
    11
    All my data is coming from an excel workbook. I add the data using the following code, and it populates the access table using a SQL statement. I am just wandering if there is a way to attach other docs to an attachments column in the database I have . Ideally I would like an attachments section on the userform in which when i press the submit button it updates the access table with the attached doc similar to what the code below does (the documents will be a range of things like word and other excel docs)


    Dim cn As ADODB.Connection
    Dim rs As ADODB.Recordset
    'Connect to the database
    Set cn = New ADODB.Connection
    cn.Open "Provider=Microsoft.Ace.OLEDB.12.0; " & _
    "Data Source=\\filename.accdb;"

    'Open a recordset
    Set rs = New ADODB.Recordset
    rs.Open "tbl_Work_Requests", cn, adOpenKeyset, adLockOptimistic, adCmdTable

    Debug.Print strSQL
    With rs
    .AddNew
    .Fields("Work_Request_ID") = UserForm1.TextBox1
    .Fields("Target Date") = UserForm1.TextBox1
    .Update

    End With

    'End_Import
    rs.Close
    Set rs = Nothing
    cn.Close
    Set cn = Nothing

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    It is usually frowned upon to use the attachment field. If you really want to use it, you can do it via DAO. I do not know if there is an equivalent using ADO. IIRC, you need to use a DAO Recordset2 and Field2 type in order to manage attachments.

  5. #5
    Baz16 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2015
    Posts
    11
    I can't see any other way for what has been asked of me than to use attachments, I have advised it may be difficult to do. How would I use a Data Acces Object, would you know the code I need to do this?

    Thanks

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    It would probably be easiest to do the entire process from Access, importing info from an Excel worksheet. It can be done using VBA from Excel, too. Actually, one thing I am not sure about is what you are trying to attach. I understand the attachments are various files like PDF, xlsx, etc. What I do not understand is where these files are. Are they somehow part of an Excel worksheet or are the paths stored within an excel worksheet's cell?

    Here is some sample code. It is not the best example. I created it helping various people. So it is a Kludge and can use some refactoring.
    Attached Files Attached Files

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Attachment field is a type of multi-value field. Programmatically saving data into multi-value field requires manipulating recordset objects, as described by ItsMe. Topic of numerous threads. https://www.accessforums.net/program...vba-21259.html

    Saving files into table will cause db bloat. Lots of large embedded files, especially image types, can quickly use up Access file size limit of 2GB.
    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.

  8. #8
    Baz16 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2015
    Posts
    11
    They are going to be word and excel documents that have been created on another colleagues home drive.

  9. #9
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    The example in post #6 includes a filepicker to navigate to files being imported.

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

Similar Threads

  1. Populate Word Userform with data from Access
    By edi dhar in forum Programming
    Replies: 5
    Last Post: 08-04-2014, 11:02 AM
  2. Exporting Attachments
    By Hamm in forum Import/Export Data
    Replies: 8
    Last Post: 10-22-2012, 08:19 AM
  3. Exporting Attachments
    By kp123 in forum Access
    Replies: 1
    Last Post: 09-25-2012, 01:19 PM
  4. Exporting Attachments to an external file
    By springa in forum Import/Export Data
    Replies: 3
    Last Post: 07-17-2011, 05:33 AM
  5. Exporting Attachments per record
    By justinwright in forum Import/Export Data
    Replies: 5
    Last Post: 06-15-2011, 09:08 AM

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