Puzzling query out pt

bknight
BronzeLounger
Posts: 1374
Joined: 08 Jul 2016, 18:53

Puzzling query out pt

Post by bknight »

I have had this query from the beginning of creating the Db. Today it presents no records and I can't find a reason.

Code: Select all

SELECT Trades.Tradedate, Day([tradedate]) AS [Day], Month([tradedate]) AS [Month], Year([tradedate]) AS [Year], Trades.Symbol, Trades.ContractMonth, Trades.Quantity, Trades.ActionID, Trades.ActionName, Trades.RawP, Trades.Price, Trades.Commission, Trades.Fees, Trades.Amount, Trades.Profit, Trades.OrderNum, Trades.Notes
FROM Trades
WHERE (((Day([tradedate]))=31) AND ((Month([tradedate]))=5) AND ((Year([tradedate]))=23))
ORDER BY Trades.Tradedate;
There are trades from yesterday. What am I missing?
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78391
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Puzzling query out pt

Post by HansV »

Shouldn't it be

((Year([tradedate]))=2023))
Best wishes,
Hans

bknight
BronzeLounger
Posts: 1374
Joined: 08 Jul 2016, 18:53

Re: Puzzling query out pt

Post by bknight »

That worked, but it has worked for 6 months with only 23. I don't understand why that is, but thanks.

User avatar
SpeakEasy
4StarLounger
Posts: 544
Joined: 27 Jun 2021, 10:46

Re: Puzzling query out pt

Post by SpeakEasy »

>it has worked for 6 months with only 23
I'm surprised

bknight
BronzeLounger
Posts: 1374
Joined: 08 Jul 2016, 18:53

Re: Puzzling query out pt

Post by bknight »

SpeakEasy wrote:
01 Jun 2023, 14:53
>it has worked for 6 months with only 23
I'm surprised
Since created ???, the year was 23 and that worked on the days it was employed, not every day, but frequently. Today was the first day that no records were retuned, prompting the thread and subsequently the comment/question.

User avatar
HansV
Administrator
Posts: 78391
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Puzzling query out pt

Post by HansV »

I don't see how this could ever have worked. The Year function ALWAYS returns the four-digit year (2023), not the two-digit year (23).
Best wishes,
Hans

bknight
BronzeLounger
Posts: 1374
Joined: 08 Jul 2016, 18:53

Re: Puzzling query out pt

Post by bknight »

HansV wrote:
01 Jun 2023, 19:41
I don't see how this could ever have worked. The Year function ALWAYS returns the four-digit year (2023), not the two-digit year (23).
I may not understand why it worked either, but it did until today.

User avatar
Gasman
StarLounger
Posts: 97
Joined: 22 Feb 2022, 09:04

Re: Puzzling query out pt

Post by Gasman »

Perhaps show the base query from where that sql is generated?
Using Access 2007/2019.
Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime.
Please, please use code tags when posting code snippets, click the </>icon.
Debug.Print is your lifesaver.

bknight
BronzeLounger
Posts: 1374
Joined: 08 Jul 2016, 18:53

Re: Puzzling query out pt

Post by bknight »

It has been changed, but
You do not have the required permissions to view the files attached to this post.

User avatar
Gasman
StarLounger
Posts: 97
Joined: 22 Feb 2022, 09:04

Re: Puzzling query out pt

Post by Gasman »

And that shows 2023 not 23 ?
Using Access 2007/2019.
Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime.
Please, please use code tags when posting code snippets, click the </>icon.
Debug.Print is your lifesaver.

bknight
BronzeLounger
Posts: 1374
Joined: 08 Jul 2016, 18:53

Re: Puzzling query out pt

Post by bknight »

That is because I changed it as mentioned in previous post, that was the change after Hans suggested it should be 2023, not 23.

User avatar
HansV
Administrator
Posts: 78391
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Puzzling query out pt

Post by HansV »

If you temporarily delete 2023 from the Criteria line, then switch from design view to datasheet view, what do you see in the Year column? Values such as 21, 22, 23? Or such as 2021, 2022, 2023? Or even a mixture?
Best wishes,
Hans

bknight
BronzeLounger
Posts: 1374
Joined: 08 Jul 2016, 18:53

Re: Puzzling query out pt

Post by bknight »

2023
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78391
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Puzzling query out pt

Post by HansV »

Yeah, that's what I expected. As I wrote in an earlier reply, the Year function returns the 4-digit year of a date 2023 in this example.

I still don't see how just 23 as Criteria could have worked...
Best wishes,
Hans

bknight
BronzeLounger
Posts: 1374
Joined: 08 Jul 2016, 18:53

Re: Puzzling query out pt

Post by bknight »

I don't know either, but it did, until it didn't.
In the same Db you have suggested a convert2number function and I would like a refinement preventing copy/paste/typing values in two fileds. Current I copy the string price in the frmFracCalculation. Hit return then paste that string into Rawp. Move back to frmFracCalculation and copy he calculated value to Price.

Code: Select all

Private Sub RawPrice_AfterUpdate()
    Me.Price = Convert2Num(Me.RawPrice)
End Sub

Code: Select all

Function Convert2Num(Price As Variant)
    Dim p As Double, p1 As Double
    
    If IsNull(Price) Then
        Convert2Num = Null
    Else
        p = InStr(Price, "'")
        If p <> 0 Then
        Convert2Num = Left(Price, p - 1) + Mid(Price, p + 1) / 32
        Else
        p = InStr(Price, " ")
        p1 = InStr(Price, "/")
        Convert2Num = Left(Price, p - 1) + Mid(Price, p + 1, p1 - p - 1) / 32
        End If
    End If
End Function

User avatar
HansV
Administrator
Posts: 78391
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Puzzling query out pt

Post by HansV »

I'm sorry, I don't understand your question. Could you try to explain it more clearly?

(I won't be able to reply immediately, so no hurry)
Best wishes,
Hans

bknight
BronzeLounger
Posts: 1374
Joined: 08 Jul 2016, 18:53

Re: Puzzling query out pt

Post by bknight »

I copy the string "price" from the trading software.
I then paste the string into the frmFracCalculater and pressenter
The string is converted to a number.
I then paste the string "price" into the RawP field, I would like this to be automatic.
I copy the converted number from the frmracCalculaor and paste that number into the price field, this I would like don automatic.
We should be able to use the code I have, but a new code can be written.

User avatar
HansV
Administrator
Posts: 78391
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Puzzling query out pt

Post by HansV »

I still don't understand. Is frmFracCalculater (or frmFracCalculation or frmracCalculaor) the only form involved, or is there another form?
Best wishes,
Hans

bknight
BronzeLounger
Posts: 1374
Joined: 08 Jul 2016, 18:53

Re: Puzzling query out pt

Post by bknight »

Yes frmTrades contains the fields that will be updated frmTrades.RawP will contain the RawPrice of the Convert2Number input while frm.Trades.Price will contain the ouput of the Convert2Number function. I tried a bit of those actions, but it isn't working.

Code: Select all

Function Convert2Num(Price As Variant)
    Dim p As Double, p1 As Double
    
    If IsNull(Price) Then
        Convert2Num = Null
    Else
        p = InStr(Price, "'")
        If p <> 0 Then
        Convert2Num = Left(Price, p - 1) + Mid(Price, p + 1) / 32
        Else
        p = InStr(Price, " ")
        p1 = InStr(Price, "/")
        Convert2Num = Left(Price, p - 1) + Mid(Price, p + 1, p1 - p - 1) / 32
        End If
    End If
    Forms!frmtrades.Price = Convert2Num
End Function

Code: Select all

Private Sub RawPrice_AfterUpdate()
    Me.Price = Convert2Num(Me.RawPrice)
    Forms!frmtrades.RawPrice = Me.RawPrice
End Sub

User avatar
HansV
Administrator
Posts: 78391
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Puzzling query out pt

Post by HansV »

So what does frmFracCalculater (or frmFracCalculation or frmracCalculaor) have to do with it?
Best wishes,
Hans