Results 1 to 11 of 11
  1. #1
    Mehvan's Avatar
    Mehvan is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2016
    Posts
    133

    Post sent amount form SubForm to MainForm

    Hello everyone

    I have mainform and subform , I connected between both , ID to ID


    In subform I added new text even I know How much sum amount in that subform ( for expamle name of that text is = "text1" , subformname is " subbuyform ", and mainform = " BuyInvoice ")

    I would like to sent amount in subform to Mainform and name is Mainform is " amount "
    but I would like to make it by VBA

    If someone can help me , I will be very pleased .

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I have mainform and subform , I connected between both , ID to ID
    You have linked the forms in the fields "ID"? Are both the "ID" field PK fields?

  3. #3
    Mehvan's Avatar
    Mehvan is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2016
    Posts
    133
    PK is for MianForm , but subform is foreign key
    Just when I brought subform to mainform even both work together in define my own I connected ID to ID

    and in Relationship I made connect between both ID to ID

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You see where having both fields named "ID" is confusing?? It is better to give informative names to fields. Fields with "ID" is usually the PK field.
    If you have a table of Employees, "EmpID", "EmpIDPK" or "EmpID_PK" are better names.
    If there is a table named WorkHours, "WorkHoursID_PK" could be the name of the PK field, with a related field to employees named "EmpIDFK" or "EmpID_FK".
    So you would have "EmpID_PK" linked to "EmpID_FK". Which is easier to know which in the PK field and which is the FK field?


    sum amount in that subform ( for expamle name of that text is = "text1" , subformname is " subbuyform ", and mainform = " BuyInvoice ")
    I would like to sent amount in subform to Mainform and name is Mainform is " amount "
    So the main form control is named "amount" and the sub form control is named "text1" ?

    The code would be something like
    Code:
    Me.amount = Me!subbuyform.Form!text1
    How are you going to execute the code? When do you want the control "amount" to update?

  5. #5
    Mehvan's Avatar
    Mehvan is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2016
    Posts
    133
    It means I will click on text1 then I will go to events after that I will use After Update as VB
    and I will write that code
    in this way I used this code but didn't give me any result ,, I don't know my ms is has a problem or I'm using wrong code
    Click image for larger version. 

Name:	Capture.PNG 
Views:	14 
Size:	11.5 KB 
ID:	27450

    after I used that code in that way I talked about on above also Didn't gave me result

    Click image for larger version. 

Name:	Capture1.PNG 
Views:	14 
Size:	19.9 KB 
ID:	27451

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Add a button next to the "Amount" control
    Click image for larger version. 

Name:	Presentation1.jpg 
Views:	13 
Size:	5.2 KB 
ID:	27452
    Create a click event for the button.
    Name the button whatever you want.
    Then paste in this code
    Code:
        Me.amount = Me!subbuyform.Form!text1

    When I create this button, this is what MY code looked like
    Code:
    Private Sub Command6_Click()
        Me.amount = Me!subbuyform.Form!text3
    End Sub
    Save it then switch back to normal view and click the button.
    The amount control should have an amount in it... hopefully $9,400.00...

  7. #7
    Mehvan's Avatar
    Mehvan is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2016
    Posts
    133
    Click image for larger version. 

Name:	Capture5.PNG 
Views:	13 
Size:	46.9 KB 
ID:	27455 I create by this way

    I mean I made that text to invisible
    because I don't want to use command for amount , I want all value comes by codes .

  8. #8
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    And the mainform controls display the values from the subform controls in the subform footer??

  9. #9
    Mehvan's Avatar
    Mehvan is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2016
    Posts
    133
    thanks for your help
    now I haven't a problem

  10. #10
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Very good...

    Good luck with your project.

    Ready to mark this solved?

  11. #11
    Mehvan's Avatar
    Mehvan is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2016
    Posts
    133
    I'm glad to found this great website for learning programming by Microsoft Access ,, really have great people in this website for helping us when We have a questions

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. Replies: 4
    Last Post: 03-30-2012, 01:47 AM
  3. Replies: 3
    Last Post: 02-17-2012, 04:43 PM
  4. Replies: 1
    Last Post: 11-29-2011, 01:37 AM
  5. Replies: 0
    Last Post: 03-14-2009, 12:33 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