I have the following code and what I would like to do is find the oldest purchase date and delete a the number of shares entered in the InputBox. This code works to delete all of DIA, put I can't get it to pass the VB StockTicker value into the SQL code...
Dim Message, Title, Default, StockTicker, Shares
Title = "Sell Stocks"
Default = ""
StockTicker = InputBox("Which stock ticker name would you like to SELL?")
StockTicker = UCase(StockTicker)
If StockTicker = Empty Then Exit Sub
Shares = InputBox("How many shares would you like to SELL?")
If MsgBox("You have chosen to SELL " & Shares & " shares of " & StockTicker & ".", vbQuestion + vbYesNo) = vbYes Then DoCmd.RunSQL "DELETE * FROM [TBL-Purchases] WHERE [TBL-Purchases].[Stock_ID] = 'DIA'" Else: Exit Sub
Eventually, I want to find the oldest purchase date and delete the number of shares entered as 'Shares' in my InputBox...
DELETE *
FROM [TBL-Purchases]
WHERE [TBL-Purchases].[Stock_ID]=StockTicker & FIRST([TBL-Purchases].[Purchase Date]), FIRST([TBL-Purchases].[Number of Shares])
GROUP BY [TBL-Purchases].[Stock_ID];