Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Access (https://www.askmehelpdesk.com/forumdisplay.php?f=441)
-   -   Help with VBA coding (https://www.askmehelpdesk.com/showthread.php?t=828653)

  • Nov 8, 2016, 02:34 PM
    hwinceFL
    Help with VBA coding
    This is to request help with VBA coding not working as expected. I am using Access 2007 under MS Win 10 x64. I have a tblAssets (Inventory) with the following structure: AssetID, AutoNumber; PerformanceType, Number; Title, Text; Description, Text; Writer1LastName, Text; Writer1FirstName, Text; Writer2LastName, Text; Writer2FirstName, Text; Writer3LastName, Text; DateofIntro, Date/Time; RightsID, Number; PrimaryLoc, Number; SecondaryLoc, Number; TertiaryLoc, Number; OnHand, Yes/No. Initially each record has a check mark (Yes) in the OnHand field. Then, I use a multi-part form to "issue out" an Asset. The primary/main form has multiple "buttons" to perform necessary functions relating a single record selected by inputs to the form(s). All of the form functions seem to perform satisfactorily (without error); however, one button (Update On Hand Status) does not make the desired change. The Event Procedure coding for that button is:
    Private Sub UpdateOH_Click()
    Dim strSQL As String
    ' Set OnHand status to "No" since Asset is being issued out.
    strSQL = "UPDATE tblAssets SET tblAssets.OnHand = " & False
    End Sub
    If further information is needed, I will quickly share it, but I would really appreciate help with where I am going wrong here. Thanks.
  • Nov 8, 2016, 04:30 PM
    ScottGem
    You are missing an execute. Assigning a value to strSQL doesn't execute the statement.

    Add

    CurrentDB.Execute strSQL, dbFailOnError

    after the strSQL= line which should be changed to:

    strSQL = "UPDATE tblAssets SET tblAssets.OnHand = False;"
  • Nov 9, 2016, 09:40 AM
    hwinceFL
    I have made the suggested coding changes and they work; however, not as desired. Although the form using this button is currently pointing to a single record, the Execute instruction effects OnHand status in ALL records of the current table to be set to "No." How can I modify that instruction so that it only updates OnHand status in the current record?
  • Nov 9, 2016, 09:45 AM
    ScottGem
    strSQL = "UPDATE tblAssets SET tblAssets.OnHand = False AND [primarykey] = " & Me.primarykeycontrol & ";"

    But even better, why not just have a checkbox and uncheck it.
  • Nov 22, 2016, 10:51 AM
    hwinceFL
    Hello ScottGem, Please accept my apology. I thought I had already responded to your help. I chose your checkbox suggestion and thus considered the issue RESOLVED. Sorry this didn't get recorded.

  • All times are GMT -7. The time now is 08:38 PM.