Results 1 to 13 of 13
  1. #1
    tonycl69 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Nov 2012
    Posts
    102

    Pre-populating a form based on one table


    Hi all, I have looked around and spent a few days trying to get my head round this one.
    I have 2 tables, one of the tables contains data that does not change and does not need editing, the table 2 holds recorded data that can be edited or new records created. What I would like is to open a form, select, from a combo, the primary data from table 1 to populate set fields that are not editiable, but still alow the user to enter new data into the rest of the form and therefore create a new record containing both table 1 and table 2 new data, I do hope this makes sense.

    Cheers

    Tony

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    after picking the combo,it will run an append qry.
    the combo can be tied to a table if you need to post different data where it has the combo pick / appd query
    pick1, qaQry1
    pick2, qaQry2

    set the combo to 2 columns, widths 1;0, to hide the query column.
    user picks the item in the 1st column then it runs the 2nd column
    Code:
    sub cmbo_afterupdate()
       docmd.setwarnings false
       docmd.openquery cmbo.column(1)     'in code, the columns start at zero , so column 2 is 1 
       docmd.setwarnings true
    
       vRec = dmax("[dataID]","table")
       me.filter = "[dataID]=" & vRec
       me.filteron = true
    end sub
    once the data is appended , grab the max ID created (or other criteria) and load the 1 record for the user.

  3. #3
    tonycl69 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Nov 2012
    Posts
    102
    Thanks for you response. Table 1 is like a lookup, nothing will be edited. What is the forms underlying table then?

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    the data you are editing is in the form
    the combo will append a new record, prepopulated, then filter on it.

  5. #5
    tonycl69 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Nov 2012
    Posts
    102
    Once I get my head round it I will give it a go. Does it matter how many columns there are in the table I want to use to populate the form? There are over 120 columns in the one table and about the same in the other.

  6. #6
    tonycl69 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Nov 2012
    Posts
    102
    When I create the append query, what is the table I am using for that query is it table 1 or table 2. Also how are the fields populated in the form?

  7. #7
    tonycl69 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Nov 2012
    Posts
    102
    I am getting an 'object required on this line 'DoCmd.OpenQuery query1.Column(1) 'in code, the columns start at zero , so column 2 is 1'

  8. #8
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    try
    vQry =combo.Column(1)
    'DoCmd.OpenQuery vQry

  9. #9
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    What I would like is to open a form, select, from a combo, the primary data from table 1 to populate set fields that are not editiable, but still alow the user to enter new data into the rest of the form and therefore create a new record containing both table 1 and table 2 new data, I do hope this makes sense.
    Doesn't really make sense. Why are you duplicating data?

    Table1 Primary key field should/would be linked to Table2 foreign key field.
    The form would have Table1 as the record source. There would be a sub form with Table2 as the record source. No need for any code.......

  10. #10
    tonycl69 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Nov 2012
    Posts
    102
    Yes I know that I have done that several times in the past with other databases.however, I do not want tables to be updated, table 2 is the tables I want updating, and tables 1 is used to populate certain fields in a form and table 2 to be updated with a new record that contains the pk from table one for when I need to print a report. There is a fk in table 2 linked to table 1 pk. Table 1 is a one to many in table 2 but there are over 1000 records in table 1.

  11. #11
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Can make the controls on the main form non-editable.
    Can use an unbound combo box to select the main form record; then add/edit the data in the sub form.

    Just saying, you are making this harder than it needs to be.....

    Good luck with your project....

  12. #12
    tonycl69 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Nov 2012
    Posts
    102
    It does help to talk about it and the more I talk about it the clearer it is becoming

  13. #13
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I totally agree!

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

Similar Threads

  1. Replies: 1
    Last Post: 08-04-2014, 07:37 AM
  2. Replies: 1
    Last Post: 01-07-2014, 09:33 AM
  3. Replies: 1
    Last Post: 11-15-2013, 11:42 PM
  4. Replies: 7
    Last Post: 09-06-2011, 08:00 PM
  5. Replies: 3
    Last Post: 07-12-2011, 02:02 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