Results 1 to 5 of 5
  1. #1
    stalk is offline Competent Performer
    Windows 8 Access 2003
    Join Date
    May 2014
    Posts
    147

    How can I update current volume in the table using FORM?

    I have a FORM linked to a table, this is to update the current volume with the volume taken at different levels.
    Here is the code I used, some how current status Vol is not getting updated in the table and then in the FORM.
    Is any thing wrong in this code? Open to any other suggestions..


    Code:
    Sub Volume_taken()
    Dim dbs As Database
    Set dbs = CurrentDb()
          dbs.Execute "UPDATE [Login_test] SET [Login_test].[Current status Vol (µl)] = " & _
                "([Estimated Vol Rec'd (µl)]- Nz([Vol taken (µl) 1],0)-Nz([Vol taken (µl) 2],0) - Nz([Vol taken (µl) 3],0))" & _
              " WHERE [Login_test].[CSID]=  " & Forms![Login_test]![CSID] & ";"                     
               MsgBox ("Current status (Vol (µl) updated in the table!!!")
               Exit Sub
    dbs.Close
    End Sub
    Private Sub Vol_taken__µl__1_AfterUpdate()
     Call Volume_taken
      End Sub
    Private Sub Vol_taken__µl__2_AfterUpdate()
    Call Volume_taken
    End Sub
    Private Sub Vol_taken__µl__3_AfterUpdate()
    Call Volume_taken
    End Sub
    CSID Number
    Estimated Vol Rec'd (µl)
    Number
    Vol taken (µl) 1
    Number
    Vol taken (µl) 2
    Number
    Vol taken (µl) 3
    Number
    Current status Vol (µl)
    Number

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Saving calculated data is often unnecessary or even bad idea. Save raw data, do calcs in queries.

    However, if the form is bound to the table and the field that needs to be updated is in the form RecordSource, an UPDATE action is not necessary.

    Have a textbox with the calculation then code can reference the textbox to save that value.

    Me.[Current status Vol (µl)] = Me.tbxCalc

    The real trick is figuring out what event to put the code in. Possibly the form BeforeUpdate event.
    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
    stalk is offline Competent Performer
    Windows 8 Access 2003
    Join Date
    May 2014
    Posts
    147
    Textbox with formula is getting updated perfectly. ( tbxcalc [control source] =[Estimated specimen Vol Rec'd (µl)]-[Vol taken (µl) 1]-[Vol taken (µl) 2]-[Vol taken (µl) 3])
    Where as the Beforeudpate event is not firing and the table is not getting updated..
    Code:
    Private Sub Current_status__Vol__µl__BeforeUpdate(Cancel As Integer)
    Me.[Current status Vol (µl)] = Me!tbxCalc
    End Sub
    Am I doing soem thing wrong!!!

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    That looks like the BeforeUpdate event of textbox, not the BeforeUpdate event of form.
    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.

  5. #5
    stalk is offline Competent Performer
    Windows 8 Access 2003
    Join Date
    May 2014
    Posts
    147
    Quote Originally Posted by June7 View Post
    That looks like the BeforeUpdate event of textbox, not the BeforeUpdate event of form.
    Actually the control name was wrong so it's not getting updated earlier. I removed the calculated field and inserted the formula in the after update event for all the 3 vol_taken and its working perfectly.



    Code:
    Private Sub Vol_taken__µl__3_AfterUpdate()
    Me.Current_vol = [Estimated Vol Rec'd (µl)] - [Vol taken (µl) 1] - [Vol taken (µl) 2] - [Vol taken (µl) 3]
    End Sub
    Thank you for pointing me in the right direction with simple solution.
    Issue Solved!!!

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

Similar Threads

  1. Add Record from Current Form to a Table
    By Smtz in forum Access
    Replies: 1
    Last Post: 08-26-2013, 03:49 PM
  2. Replies: 7
    Last Post: 09-21-2012, 11:09 AM
  3. Replies: 3
    Last Post: 09-18-2011, 03:46 PM
  4. Run Update Query on Current Record in Form
    By c3pse in forum Queries
    Replies: 3
    Last Post: 08-14-2010, 05:40 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