Results 1 to 4 of 4
  1. #1
    tcox's Avatar
    tcox is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Oct 2015
    Posts
    46

    Help with UPDATE


    to start I apologize that I'm running back here for every little problem I'm having. I have truly searched google to try to find the answers before I post. I need to take a class that explains how VBA is to be structured.

    The goal of this code is to take an entered number, capsules_ran in this case and populate it to the corresponding order_details field for all parts in that order.
    It takes the order number from a combo box and the capsules ran from a text box.

    Code:
    Private Sub CapsuleAutoFill_Click()
    Dim SQL As String
    SQL = "UPDATE T_Order_Details" & _
    "SET [T_Order_Details].[Capsules_Ran] =  [Me.TXT_CapsulesRan]" & _
    "WHERE Order_ID = Me.CBO_OrderNumSel "
    
    
    DoCmd.RunSQL SQL
    
    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
    53,770
    CurrentDb.Execute "UPDATE T_Order_Details SET [Capsules_Ran] = " & [Me.TXT_CapsulesRan] & " WHERE Order_ID = " & Me.CBO_OrderNumSel

    Assumes both fields are number type.
    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
    tcox's Avatar
    tcox is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Oct 2015
    Posts
    46
    I had a little trouble with the code, but got it to work with locally stored variables.
    It was giving Run time Error 2465
    Here is the complete function. I'm working on learning how to implement error handling.
    For example, a field is not entered and is considered Null.

    Code:
    Private Sub CapsuleAutoFill_Click()
    Dim LintCapsules As Long
    Dim intOrderIndex As Integer
    
    On Error GoTo Error_Message
    Exit Sub
    Error_Message:
    Select Case Err.Number
    Case Else
    MsgBox "Please fill in form"
    End Select
    
    LintCapsules = Me.TXT_CapsulesRan
    intOrderIndex = Me.CBO_OrderNumSel
    
    CurrentDb.Execute "UPDATE T_Order_Details SET [T_Order_Details].[Capsules_Ran] = " & LintCapsules & " WHERE Order_ID = " & intOrderIndex
    
    DoCmd.Requery "T_Order_Details Query Subform1"
    
    End Sub

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    The error handler code goes to end of procedure.

    Review: http://allenbrowne.com/ser-23a.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.

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

Similar Threads

  1. Replies: 6
    Last Post: 11-05-2014, 05:27 PM
  2. Replies: 7
    Last Post: 08-26-2013, 06:05 AM
  3. Replies: 2
    Last Post: 08-30-2012, 07:59 AM
  4. Replies: 4
    Last Post: 11-10-2011, 03:41 PM
  5. Replies: 1
    Last Post: 01-22-2011, 12:23 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