Results 1 to 2 of 2
  1. #1
    todmac is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    20

    Update using each record in a form

    I am trying to get a user to be able to record a Cheque Number and then on a form key in the associated claim number and $ amounts associated with it.
    I then want to run a procedure to go through each record on the form, find the associated claim number in the table claims and update the amount paid with the $ amount.
    I tried to write the following code but it doesn't seem to be going through the records on the form like I had hoped.


    Code:
    Private Sub Command6_Click()
    Dim CQNum As String
    Dim WoNum As Integer
    Dim Amount_Paid As Currency
    CQNum = InputBox("Please enter the Cheque Number you wish to Process.", "Cheque Number")
    If StrPtr(CQNum) = 0 Then
        
        Exit Sub
            ElseIf CQNum = "" Then
            MsgBox "You did not enter a Cheque Number"
            Exit Sub
            End If
    
    DoCmd.OpenTable "Cheque", acViewNormal, acAdd
    Dim n As Recordset
    Dim Strsql As String
    Dim db As Database
    Set db = CurrentDb
    Strsql = "Update Claims SET Claims.Amount_Paid = " & Forms!Cheque.Amount & "  AND set Claims.chq_number = " & CQNum & " WHERE claims.Claim_Number = " & Forms!Cheque.Claim_Number & ""
     
        Do Until Forms!Cheque.EOF
        
        CurrentProject.Connection.Execute (Strsql)
        
        Loop
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Why do you open table?

    The code does not move to each record to read its data. You would see the cursor move to each record row.

    An alternative is to open a RecordsetClone of the form's data and cycle through the RecordsetClone.

    I have to wonder why this form is not bound to the destination table and user data entry just goes straight into the table?
    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.

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

Similar Threads

  1. Update Table after Record Update with Form
    By speciman_A in forum Forms
    Replies: 25
    Last Post: 10-31-2014, 01:00 PM
  2. update record via form
    By abernut in forum Access
    Replies: 7
    Last Post: 02-14-2013, 12:38 PM
  3. Update record form
    By Stika in forum Forms
    Replies: 3
    Last Post: 12-16-2012, 02:54 AM
  4. Replies: 2
    Last Post: 10-10-2012, 07:01 AM
  5. same form for new and update record
    By lizu in forum Forms
    Replies: 3
    Last Post: 06-20-2011, 08:34 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