Results 1 to 8 of 8
  1. #1
    AlisonP is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Location
    Northern CA
    Posts
    13

    Data entry subform: how to add a field in the record but not on subform

    Hi, I am a newbie to Access VB programming, much enjoying the learning process. I have a question that may be simple but I have been unable to find the answer in my usual resources. I have a form that has one unbound control where the user enters a SampleCode. The VB code behind that control does a number of validation checks. Then the user enters multiple records of data for that SampleCode on a subform. When each record is written to the table from the subform, I want to include in each record the SampleCode from atop the main form. I understand how to get the SampleCode from the main form, but I haven't been able to figure out how to put it in the data table associated with the subform. How to do that? Looks like one way that I can do it is to put a control on the subform, and set it to visible = false (and make sure that tabbing skips it?), and then populate it in the VB code for that control in the subform. Is that the right way to do it? Is there a better way? Thanks for any advice.

  2. #2
    khalid's Avatar
    khalid is offline MS-Access Developer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2010
    Location
    Kuwait
    Posts
    244
    I have a form that has one unbound control where the user enters a SampleCode. The VB code behind that control does a number of validation checks.
    your question is not clear.... what code you want to enter? and why???

    Then the user enters multiple records of data for that SampleCode on a subform. When each record is written to the table from the subform, I want to include in each record the SampleCode from atop the main form.
    What is the purpose of inserting the code to every record???
    Is there a field in your table to save this samplecode to your table????

  3. #3
    AlisonP is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Location
    Northern CA
    Posts
    13
    [QUOTE=khalid;66755]your question is not clear.... what code you want to enter? and why???

    What is the purpose of inserting the code to every record???
    Is there a field in your table to save this samplecode to your table????


    Yes, there is a field in the table to save the sample code. That is the primary data key for the table and needs to be in the table so that each record has the sample code identified (there are a varying number of records corresponding to each sample code).

    Thank you for helping.

  4. #4
    khalid's Avatar
    khalid is offline MS-Access Developer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2010
    Location
    Kuwait
    Posts
    244
    still confused: you may be wanted to save the primary key to foreign key to another table with one to many relationship????

    assuming that your tables are properly normalized with foreign and primary keys, and on the subform, you can easily bound your primary key to your subform table's foreign key.

    Is that you mean???

  5. #5
    AlisonP is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Location
    Northern CA
    Posts
    13
    Sorry, I misspoke and created confusion. The unbound control that is being entered on the main form is the primary key in a table of sample codes. The subform is for adding the many data records corresponding to this sample code, and is it the sample code as foreign key that I want to write to the subform table records. Yes, the tables have been normalized with primary and foreign keys. Hopefully this is clearer.

    How do I insert that foreign key into the subform table records when there is no control for it on the subform?

  6. #6
    vicrauch is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    Sacramento
    Posts
    27
    Put the foreign key field on your subform, and the set visible = false for that field. That is how you update the table from the subform. By hiding the field, the user will not see it, but your database will see it and be able to save that data to the table.

  7. #7
    AlisonP is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Location
    Northern CA
    Posts
    13
    Thanks. That was my original thought as I said in my first posting, but I was wondering if there was a better way. This forum is very helpful to me as I am learning the VB code.

  8. #8
    AlisonP is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Location
    Northern CA
    Posts
    13
    I am posting a more complete response in case any other novice looks to this thread for an answer.

    In addition to Vic's suggestion, I needed to change the Control Source to the field in the table, and set the Default Value for that control to be =[Forms]![MainFormName].[MainFormFieldControlName]

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

Similar Threads

  1. locking data in subform after record save
    By Nixx1401 in forum Forms
    Replies: 24
    Last Post: 05-31-2011, 01:48 PM
  2. Data Entry in SUBFORM
    By flsticks in forum Access
    Replies: 1
    Last Post: 04-03-2011, 08:07 AM
  3. Replies: 1
    Last Post: 03-15-2011, 03:53 PM
  4. Replies: 0
    Last Post: 09-01-2009, 12:33 PM
  5. Subform Data Entry Issue
    By yuriyl in forum Forms
    Replies: 3
    Last Post: 05-14-2009, 08:49 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