Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    Mehvan's Avatar
    Mehvan is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2016
    Posts
    133

    Post Update Main Form and SubForm into Table

    Hello Everyone

    I have SaleInvoice MainForm related with SubForm , and I have another table its name is Details , I want when I update data in MainForm and SubForm , and then click on "cmdButton" automatically update data in table name Details


    I made code INSERT INTO , but Update isn't work

    This is INSERT INTO :

    Code:
     If DLookup("[id]", "details") = [SaleID] Then    Exit Sub
        
        Else
        DoCmd.RunSQL "INSERT INTO Details ( ID, sDate, CustomerName, ItemsName, Qy, Price, Total )SELECT Sale.SaleID, Sale.SaleDate,     Sale.CustName, Sub.Items, Sub.Qy, Sub.Price, Sub.Total FROM Sale INNER JOIN Sub ON Sale.SaleID = Sub.SubID"
    
     End If
    UPDATE :
    Code:
        DoCmd.SetWarnings False        CurrentDb.Execute "UPDATE  Details " & _
            "SET ID =" & Me.SaleID & _
            ", sDate = #" & Me.SaleDate & "#" & _
            ", CustomerName ='" & Me.CustName & "'" & _
            ", ItemsName ='" & Me.Sub!Items & "'" & _
            ", Qy = " & Me.Sub!Qy & _
            ", Price =" & Me.Sub!Price & _
            ", Total =" & Me.Sub!Total & _
            "WHERE ID = " & Me.SaleID
    
    
        DoCmd.SetWarnings True
    Can someone help me , please ?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Why do you need to use INSERT INTO? Are your forms not bound to tables?
    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
    Mehvan's Avatar
    Mehvan is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2016
    Posts
    133
    related with another table
    I want INSERT ( Sale , Purchase , Return Purchase , Return Sale , Income ) INTO Details Table
    I want to Make " Customer account statement " , When one Customer come to me and want his account statement , I will give him Details Table

  4. #4
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    But you have all that information already stored in your order tables, simply query them from the original source, don't duplicate data.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    Mehvan's Avatar
    Mehvan is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2016
    Posts
    133
    you're right , but it's difficult I be able to create query all these 5 Invoice in one query .

  6. #6
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    It shouldn't be, simply group by the customers unique account number?
    What difficulty are you having with querying the data?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  7. #7
    Mehvan's Avatar
    Mehvan is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2016
    Posts
    133
    I want to create that Table the same this below picture

    Click image for larger version. 

Name:	Capture.PNG 
Views:	32 
Size:	17.8 KB 
ID:	35671

    This is a small example , I want to do it by using INSERT And UPDATE
    Can you correct my UPDATE code , please ?

  8. #8
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    You are heading for a world of pain trying to store your information in this fashion.
    The rolling amount must be calculated in a query or a report and not stored, as there is no way to guarantee the amount is correct if you make or correct a mistake.

    By calculating it from your source data you ensure it is always accurate.
    Copying it in this way and format is against all good database design advice.

    Good luck with your project.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  9. #9
    GinaWhipp's Avatar
    GinaWhipp is offline Competent Performer
    Windows 7 64bit Access 2013 32bit
    Join Date
    Jul 2011
    Location
    Ohio, USA
    Posts
    377
    Hmm, no what you want is a Running Sum query (Google that) that will be as you pictured above.

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Easiest to calculate running sum on report. Textbox on report has RunningSum property.
    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.

  11. #11
    GinaWhipp's Avatar
    GinaWhipp is offline Competent Performer
    Windows 7 64bit Access 2013 32bit
    Join Date
    Jul 2011
    Location
    Ohio, USA
    Posts
    377
    @June,

    Not sure that would work in this case as it's more like a check register. The math has to happen across before down.

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    It can be done. RunningSum on expression. =Nz([Qy])*Nz([Price])-Nz([IncomeAmount])

    Shouldn't that last value be 80?
    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.

  13. #13
    Mehvan's Avatar
    Mehvan is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2016
    Posts
    133
    My English isn't very good , because of that maybe you didn't understand What I need to do

    I want to create Customer Account : for example
    if someone come to me and he wants his account , and told me , I want to give me , my account , What I bought in this year with ItemsName as appear in photo

    when he bought something such as : SaleInvoice ( SaleID , Date , CustName , ItemName , Qy , Price , Total , Net ) , when He return something I want automatically appear under the same Table (SaleID , Date , CustName , ItemName , Qy , Price , Total , Net) just will say , this is return and automatically decreases of his account
    I mean anything related with that Customer appear in one page ( Sale , Return , Stock and Income ) with them details .

    I know to create Calculate
    I will use the same this code , I used in another project
    Code:
    Total: (select(Sum( [SumOfFirstTotal] ) + Sum( [SumOfSaleTotal] ) - Sum( [SumOfReturnTotal] ) - Sum( [SumOfComeTotal] ) - Sum( [SumOfSaleCash] )) from [Q_CustomersAccounts] where C1.[AccountDate] >= [AccountDate] and C1.[CustName] = [CustName] )
    Just I want to correct my code in Update
    INSERT INTO , work without problem , but I have a problem with UPDATE

    When I change something in Invoice and click on Update button , change it .

    Click image for larger version. 

Name:	Capture.PNG 
Views:	22 
Size:	11.1 KB 
ID:	35679

  14. #14
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    UPDATE action using an aggregate query as source - won't work, period.

    If you can calculate the totals for update then you can calculate whenever needed.

    Saving aggregate data (also called dependent data - data that is calculated from other data) is normally not advisable. Review http://allenbrowne.com/AppInventory.html
    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.

  15. #15
    Mehvan's Avatar
    Mehvan is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2016
    Posts
    133
    Can you correct this code , please ?

    Code:
        DoCmd.SetWarnings False        CurrentDb.Execute "UPDATE  Details " & _
            "SET ID =" & Me.SaleID & "" & _
            ", sDate = #" & Me.SaleDate & "#" & _
            ", CustomerName ='" & Me.CustName & "'" & _
            ", ItemsName ='" & Me.Sub!Items & "'" & _
            ", Qy = " & Me.Sub!Qy & "" & _
            ", Price =" & Me.Sub!Price & "" & _
            ", Total =" & Me.Sub!Total & "" & _
            ",FROM Sale INNER JOIN Sub ON Sale.SaleID = Sub.SubID"
    
    
        DoCmd.SetWarnings True

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 02-11-2018, 02:06 PM
  2. Replies: 1
    Last Post: 11-04-2015, 07:25 AM
  3. Replies: 8
    Last Post: 05-30-2013, 05:06 PM
  4. Update Main Form From Subform
    By burrina in forum Forms
    Replies: 7
    Last Post: 02-06-2013, 03:55 PM
  5. Requery subform after update of main form
    By gemadan96 in forum Forms
    Replies: 3
    Last Post: 10-17-2012, 02:33 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