1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Print attachments from MS Access

Discussion in 'Business Applications' started by Alchemi, Jun 14, 2019.

Advertisement
  1. Alchemi

    Alchemi Thread Starter

    Joined:
    Sep 13, 2018
    Messages:
    12
    First Name:
    Chris
    Hello,

    I've put together a joint system between HR and myself to where they enter in basic employee information and I keep track of their training in the Quality program. Now we don't have competing systems, we can actually do safety programs, and I will finally be able to keep track of current employees. (So annoying when days before an audit you find out we've hired a dozen people and none have completed any training.)

    It's moving along swimmingly, except I'd like to add a feature. I'd like a button for HR to press that generates all the documents an employee has to read. When an employee starts, they will be assigned a position in the company, like "Line C Technician." For them to properly do their job, they have to read about things like the Sanitation program, how to operate a certain machine, or what to do when the product doesn't turn out right. Their position is different than someone like in Sales, who have their own training program.

    So I've got a table of "Master Documents," a list of all the documents as well as pdfs of them. I also have a table called "Required Documents for Job Positions" where certain documents are called up from the Master Documents table. The "Roster" table contains all the employee information including their assigned position.

    I've been researching how to get a program to print out the documents. Unfortunately for me what I see happening, on the Roster's companion form I have to call up the list of documents referenced on the Job Positions tables, who's actual pdfs are on the Master Documents table.

    At this point I kind of throw my hands up in the air. I'm not seeing a clear path through this given the programming examples I've seen so far. They all seem to deal with a table that's right there at the first level, not a couple away. Any advice?
     
  2. lunarlander

    lunarlander

    Joined:
    Sep 21, 2007
    Messages:
    10,816
    I don't use Access, but you can look up the syntax for referencing items. Maybe you might need to do a table join.
     
  3. Chawbacon

    Chawbacon

    Joined:
    Jul 9, 2018
    Messages:
    378
    First Name:
    Jack
  4. Alchemi

    Alchemi Thread Starter

    Joined:
    Sep 13, 2018
    Messages:
    12
    First Name:
    Chris
    Sorry so long to come back. Lots of things happening, had to build two other systems quickly...

    Hello Chawbacon, I took a look at OBP's solution and it appears designed to pull files out of directory. The files I need to print are inside a database table.

    So let's use my shortest list as an example. I have the president of our company having to read our cGMP document. I'd like the macro to go to the first item in their list (this document), and call up this file and print it.

    Like Lunarlander said, I probably need to use referencing but I'm not up on writing SQL. I can kind of read it.

    Now, the query used to build the table of things they need to read, I can rig that to also include the document. But I'm not sure how to get it out. I think if I can do that I would be on the right path. Any advice?
     
  5. Alchemi

    Alchemi Thread Starter

    Joined:
    Sep 13, 2018
    Messages:
    12
    First Name:
    Chris
    OK, I think I've had an epiphany here...

    After I made my post I added to the query that runs the subform for the required training. Now it also holds the pdf file that I need. So what I'd like to do is run the printer program not on a table like I've seen in other places, but on the query. So how would I handle the green? I mean, can it run from a query, loop through it like a table, and print out what I need?

    Private Sub Command175_Click()
    Dim dbs As DAO.Database
    Dim rst As DAO.Recordset2
    Dim rsA As DAO.Recordset2
    Dim fld As DAO.Field2

    'Get the database, recordset, and attachment field
    Set dbs = CurrentDb
    Set rst = dbs.OpenRecordset("Required_SOPs_sfrm_qry")
    Set fld = rst("Image")

    'Navigate through the table
    Do While Not rst.EOF

    'Get the recordset for the Attachments field
    Set rsA = fld.Value

    'Print all attachments in the field
    Do While Not rsA.EOF

    Debug.Print , rsA("FileType"), rsA("FileName")

    'Next attachment
    rsA.MoveNext
    Loop

    'Next record
    rst.MoveNext
    Loop

    rst.Close
    dbs.Close
    Set fld = Nothing
    Set rst = Nothing
    Set dbs = Nothing

    End Sub
     
  6. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...

Short URL to this thread: https://techguy.org/1228605

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice