Results 1 to 7 of 7
  1. #1
    jwd is offline Novice
    Windows 7 32bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    4

    2 forms and one subform update

    I have 2 forms and 1 subform, with 1 text field in the subform. I want to populate the subform and the text field from formB. Should be pretty simple



    formA
    Name: subform1
    Name: text field1 (that is the name of text field in the subform)

    formB
    this is where I want to populate text field1 in the subform1 in FormA

    I think I need a text field in FormB so I will call that text field3


    How would I go about this? Is it in the after update procedure? and if so how would you write it?

    Thanks for taking the time to read my question

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    Form A and Form B are both open? Form A has the subform? You want to populate a textbox on Form B with a value from subform? Why do you need to duplicate data?

    The trick is figuring out which event. AfterUpdate of what - form or control? The syntax depends on which form the code is behind.
    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
    Rod is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    Depends upon what event should trigger the population of the subform. If that event is a change to the textbox value in form B then either the before update or after update events may be used. I would suggest the after update event (as you have proposed) since the before update event can be problematical if you want to go to another control.

    How would I write it? The most straightforward way for you is to do the following:

    1. Check that form A is loaded. If not, do nothing.

    If CurrentProject.AllForms("FormA").IsLoaded Then
    ...

    2. Poke the value of form B's textbox into the textbox on form A's subform. The addressing is a bit tricky.

    Forms("FormA").sfrForm.Form![text field1] = Me.mytextbox

    Think I've got that right - I don't do it this way. The term highlighted in red is the name of the subform control on form A. I have used an exclamation mark for safety; I think a period would work just as well.


    PS. June - again! Good thing we always seem to be saying the same thing.
    Last edited by Rod; 11-20-2012 at 06:25 PM. Reason: Added PS

  4. #4
    jwd is offline Novice
    Windows 7 32bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    4
    Thanks for the quick responce. I don't think I duplicating data. This has to do with hrly wages. I want formB to populate formA and the subform, text field, so the user does not have to type in the hrly wage everytime a record is created in the subform.

    You want to populate a textbox on Form B with a value from subform? No just the opposite. I want to populate FormA from FormB
    Last edited by jwd; 11-20-2012 at 06:39 PM. Reason: answer more clearly

  5. #5
    jwd is offline Novice
    Windows 7 32bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    4
    Not to good at codes, so little confused here Rod.


    If CurrentProject.AllForms("FormA").IsLoaded Then

    Forms("FormA").sfrForm.Form![text field1] = Me.mytextbox

    Is this what I paste into the text box on FormB in the "after update" event

    Thanks for the quick reply

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    You need to replace with your actual form and control names.

    I believe Rod is suggesting (as do I) that you name the subform container control something meaningful and different from the form object that it holds. Something like sfrDetails or ctrDetails.
    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.

  7. #7
    Rod is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    Is this what I paste into the text box on FormB in the "after update" event
    Here's what you paste into the after update event for the textbox on FormB:

    Code:
    If CurrentProject.AllForms("FormA").IsLoaded Then
       Forms("FormA").sfrForm.Form![text field1] = Me.mytextbox
    End If
    Blue - change the name to the your form name if not FormA
    Red - change sfrForm to the name of the subform control on FormA
    Maroon - change to the name of your subform textbox if not "text field1." I think Form.[text field1] also works; never sure when brackets have to be used. If there are no special characters in your textbox name the use something like Form.Myname.
    Orange - change "mytextbox" to the name of your textbox on FormB


    PS. Again we're overlapping! Yes, I have forced myself into the habit of naming subform controls with the tag "sfr" to differentiate them from the form itself. So much confusion is caused because Access defaults the name of the control to the name of the form.

    I actually use Custom Events for tasks like this but try explaining that in 2 column inches.
    Last edited by Rod; 11-20-2012 at 07:16 PM. Reason: PS

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

Similar Threads

  1. Replies: 1
    Last Post: 11-07-2012, 05:31 PM
  2. Web Forms to Update Access DB
    By GCPDblue in forum Database Design
    Replies: 0
    Last Post: 05-30-2012, 04:50 PM
  3. Replies: 3
    Last Post: 04-17-2012, 10:28 AM
  4. Update field in table after update on a subform
    By jpkeller55 in forum Queries
    Replies: 3
    Last Post: 09-30-2010, 08:02 PM
  5. Auto Update Forms
    By Vikki in forum Forms
    Replies: 1
    Last Post: 02-09-2010, 10:51 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