Results 1 to 4 of 4
  1. #1
    accessuser1023 is offline Novice
    Windows Vista Access 2007
    Join Date
    Dec 2012
    Location
    Iowa City, IA
    Posts
    1

    PK of fields in a form that is sourced by a query

    all,

    this is a cross post from AWF:

    http://www.access-programmers.co.uk/...d.php?t=239253

    Here's my requirement, which I am looking for the easiest way out on:



    => Grab all form fields that have control sources which are sourced PKs at the lowest-level (table). Problem is, many of these forms are bound to queries which involve multiple tables. I know there is a way, but I don't have any of the Access OOP model documented. So that leaves me with skimming the help articles forever to find the enums and props I need.

    help anyone? this isn't really my job and the DB architect is not a professional which is why the structure is very prone to corruption. but they are not worried about that (per the other thread).

    thanks all, and Merry Christmas to everybody here.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,919
    This shows code to get the PK of a given table http://www.utteraccess.com/forum/Pri...ed&pid=1086591

    The code could be modified to loop through all tables in the db.

    Now determining which forms have those fields is another issue. Why do you need this?
    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.

  3. #3
    help_me_with_access is offline help_me_with_excel
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    262
    Quote Originally Posted by June7 View Post
    Why do you need this?
    like I stated June, the database architect is not a pro. and thus, patch work will ensure for the person from now on. I don't lecture people if they contact me to solve a problem. I give them advice on how they got to the problem (if they can emotionally handle it), what the correct way to design a database is, and then tell them I can solve the problem if there's any solution available or not, regardless of how "piecemeal" it is.

    a check is a check, in this guys' view. but in all fairness to small business people as well, the USA economy and the panic that consumers run on these days, a lot of times that doesn't really give much time to think about doing things "right" for small business people if they are doing the tech work themselves. so I really don't blame this person for doing what he can with the time he's got.

    to re-iterate, I need it because of a lack of planning and lack of knowledge about proper base-lining by the original author. nothing can be done about it at this point, unfortunately. thanks for asking though. eventually people do learn.

    I knew this could be done the minute I got the request, but as I said I just don't have the OOP model of VBA documented well enough to establish the steps I need to take to get this done without taking a day or so to research it.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    Here's a routine to get the recordsource for each form in a database.

    Code:
    '---------------------------------------------------------------------------------------
    ' Procedure : getFormRecordSource
    ' Author    : Jack
    ' Date      : 29-12-2012
    ' Purpose   : To get the recordsource of each form in the current access database
    ' Outputs formname and recordsource to the immediate window
    '---------------------------------------------------------------------------------------
    ' Last Modified:
    '
    ' Inputs: N/A
    ' Dependency: N/A
    '--------------------------------------------------------------------------
    '
    Sub getFormRecordSource()
            Dim afrm As AccessObject
            Dim frm As Access.Form
    10       On Error GoTo getFormRecordSource_Error
    
    20      For Each afrm In CurrentProject.AllForms
            
    30          If Not afrm.IsLoaded Then
    40            DoCmd.OpenForm afrm.name, acDesign, , , , acHidden
                  
    50            Debug.Print afrm.name & "  -- " & Forms(afrm.name).RecordSource
    60            DoCmd.Close acForm, afrm.name
    70          Else
    80            Debug.Print afrm.name & "  -- " & Forms(afrm.name).RecordSource
    90          End If
              
    100     Next afrm
    
    110      On Error GoTo 0
    120      Exit Sub
    
    getFormRecordSource_Error:
    
    130       MsgBox "Error " & Err.number & " (" & Err.Description & ") in procedure getFormRecordSource of Module AWF_Related"
    End Sub
    It may help. Not all forms have record sources.

    My guess as to how it would be set up is along this line:

    Code:
    For each Form in the Database
      For each Control on the Form
       'you will need to deal with type of Control
        get the controlsource or rowsource
        write the Formname, ControlName and Rowsource/controlsource value to a table FormControlInfo
      next control
    next Form
    Subsequently;
    Code:
    For each Table in the FormControlTable
       Identify the Pks
       Write Tablename, PrimaryKey (may be compound) to some final location
    Next Table

    Research Google 'identifying all controls on a form MS Access'

    Some links
    http://www.devhut.net/2010/12/05/ms-...ols-on-a-form/
    http://stackoverflow.com/questions/3...n-a-subform-ac

    But there are many more

    Good luck with the project.

    EDIT::::
    Following the original post I found this link from Allen Browne which may be helpful
    http://allenbrowne.com/ser-73.html
    Last edited by orange; 12-29-2012 at 05:17 PM. Reason: More info added to orig post

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

Similar Threads

  1. Using form fields as query criteria
    By bener in forum Queries
    Replies: 3
    Last Post: 10-28-2011, 12:54 PM
  2. Passing form fields criteria to a Query
    By yosik20 in forum Queries
    Replies: 1
    Last Post: 05-12-2011, 04:24 AM
  3. Replies: 1
    Last Post: 05-04-2011, 03:51 PM
  4. Replies: 6
    Last Post: 03-14-2011, 09:37 AM
  5. Replies: 3
    Last Post: 02-08-2011, 10:25 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