Ask Experts Questions for FREE Help !
Ask
    hwinceFL's Avatar
    hwinceFL Posts: 45, Reputation: 1
    Junior Member
     
    #1

    Nov 8, 2016, 02:34 PM
    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.
    ScottGem's Avatar
    ScottGem Posts: 64,966, Reputation: 6056
    Computer Expert and Renaissance Man
     
    #2

    Nov 8, 2016, 04:30 PM
    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;"
    hwinceFL's Avatar
    hwinceFL Posts: 45, Reputation: 1
    Junior Member
     
    #3

    Nov 9, 2016, 09:40 AM
    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?
    ScottGem's Avatar
    ScottGem Posts: 64,966, Reputation: 6056
    Computer Expert and Renaissance Man
     
    #4

    Nov 9, 2016, 09:45 AM
    strSQL = "UPDATE tblAssets SET tblAssets.OnHand = False AND [primarykey] = " & Me.primarykeycontrol & ";"

    But even better, why not just have a checkbox and uncheck it.
    hwinceFL's Avatar
    hwinceFL Posts: 45, Reputation: 1
    Junior Member
     
    #5

    Nov 22, 2016, 10:51 AM
    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.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Can VBA do this for me? [ 7 Answers ]

Refer attachment; For sheet "SPPA" cell "D18" value to be recorded on sheet "HO plan" cell "T7", and this is where it gets nasty, as the date rolls over on the "SPPA" sheet cell "F1", so must the macro record the new value in the next cell for sheet "HO plan", ie: If "SPPA" sheet cell "F1"...

Color coding on data line does not match jack color coding [ 1 Answers ]

Installing cat5 data standard blue/white-blue, green/white-green, orange/white-orange, and brown/white brown but the wall mount I purchased has black, yellow, white, green, blue, orange, brown, and green. What color line do I connect Where?

Can this be done using VBA? [ 5 Answers ]

Ok - I have a spreadsheet that is exported from an application I use at work. It formats the data in a manner that makes it really difficult to manipulate but I think I've worked out a solution that gets me what I need; only it is very tedious. The data starts in row 16 of the sheet. There is...

Color coding on line does not match jack color coding [ 11 Answers ]

The line going into the old phone jack has orange, green, blue and 3 white wires in it. Bought a new jack at Radio Shack and the colors of the wires in the replacement jack are red, green, black and yellow. Verizon repair was at best, snotty in telling me "we cannot tell you how to do repairs...


View more questions Search