Results 1 to 11 of 11
  1. #1
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142

    Store Reference to Access Objects in a Field

    My database has a Jobs table. I have several reports to run on any one job, and some of these reports are actually slight variations on other reports. (I just copy and paste and make my tweaks)



    I would like to add a field to my Jobs table to store a reference to a preferred report variation, sort of a foreign key that references an access object instead of a another table. How should I approach this?

    Id like it to be dynamic such that in the future the user can copy/paste/tweak their own custom report. They could simply then find their custom report in a drop down field and select it as default for that particular job.

    Finally, could this same concept be done with variations of forms?

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    It really depends on how you plan to use these objects but storing Report and Form names is certainly possible.

  3. #3
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    So I was poking around the hidden System Object tables, it looks like the information I'm after is stored in the MSysObjects table, with reports having a type -32764. Is there any reason I shouldn't utilize these tables? My Job table could have a foreign key to the MSysObjects table, couldn't it?

    Of course I won't do any updating/appending in the system tables. (edit) Looks like I'm not able to manually edit the tables anyway, so no worries there I suppose.

  4. #4
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,840
    Those tables will allow you to enumerated Access objects, but they won't identify which report is Joe's and which is Mary's.
    They could simply then find their custom report in a drop down field and select it as default for that particular job.
    I don't think they're suitable for what you're trying to do unless all you want is a combo list of reports, which won't be specific to their name. They will see everyone's reports.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    I'd store the report object's pk as a fk in the jobs table, right? Can I open a report or form with it's pk in vba? Of course I can just look up its name now..

  6. #6
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,436
    Need more information on how you want this to work.

    How many reports are involved? How do the custom reports differ? Do they have different display fields? Different data sources? Different grouping and sorts? Is each and every custom report a distinct report in the Navigation Pane? What is the lifetime of a custom report - one time use or permanent?
    How would a user identify "his" custom reports in a list of reports? Do you have a report naming convention?

  7. #7
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    So I'm thinking I'd just query the msysobjects table for object's with type -32764, assuming that's the type for all reports, and id further filter those results by searching for a prefix in the report's name, in this case any report name that starts with "SOV_". I'd have to find away to make sure the user knows to leave this identifying prefix in the report's name, maybe there's a better way to identify them?

    Custom reports would usually differ in grouping and fields displayed. They could differ much more dramatically, I'm leaving that up to them. For my use right now I'm thinking I need about 5 different variations on this particular report. Lifetime is permanent. As for navigation pane, before it occurred to me to make this dynamic it was just going to be a button for each report variation, now I'm thinking I'd use a combobox to show them. The combo would be populated as described in the first paragraph.

  8. #8
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,436
    Something like this? The reports are in a list box with a row source based on a query of MSysObjects table. You could filter this any way needed on a report name prefix.
    I use this technique often and users like it.
    Click image for larger version. 

Name:	frmReports.JPG 
Views:	9 
Size:	31.4 KB 
ID:	30104

  9. #9
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    All right! That's what I needed to know, you identify reports by the type field? A report is always -32764?

  10. #10
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,840
    here's how to identify all/most of the object types
    http://access.mvps.org/access/queries/qry0002.htm

  11. #11
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,436
    Here's the query (Named qReports):
    Code:
    SELECT MsysObjects.Name AS rptName
    FROM MsysObjects
    WHERE (((Left$([Name],1))<>'~') AND ((MsysObjects.Type)=-32764))
    ORDER BY MsysObjects.Name;
    And here's the rowsource for the listbox:
    Code:
    SELECT rptName from qReports ORDER BY rptName;

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

Similar Threads

  1. Replies: 16
    Last Post: 05-08-2017, 04:12 PM
  2. Replies: 2
    Last Post: 04-27-2016, 06:56 AM
  3. reference objects on subform
    By gammaman in forum Modules
    Replies: 2
    Last Post: 08-27-2015, 07:31 AM
  4. Replies: 9
    Last Post: 04-01-2014, 05:06 PM
  5. Replies: 6
    Last Post: 12-19-2013, 12:34 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