Solved Sql outcome as a label?

mamradzelvy

Member
Local time
Today, 23:25
Joined
Apr 14, 2020
Messages
144
Hi,
I can't find a way to run a sql code, namely this: SELECT sum(dbCash.CashTotal) FROM dbCash; and make it's output a label's .caption.
Anybody knows how to do that?
 
add code to the Form's Load Event.

private sub form_load()
me.label1.Caption = Nz(DSum("CashTotal", "dbCash"), 0)
end sub
 
add code to the Form's Load Event.

private sub form_load()
me.label1.Caption = Nz(DSum("CashTotal", "dbCash"), 0)
end sub
Thank you Arnel, i'm trying to also format it to Currency, is there a way to do that?
 
Did you search?

What have you tried?

Try:
Me.Label1.Caption = Format(Nz(DSum("CashTotal", "dbCash"), 0), "Currency")
 
Did you search?

What have you tried?

Try:
Me.Label1.Caption = Format(Nz(DSum("CashTotal", "dbCash"), 0), "Currency")
I did search and i tried a couple things, but nowhere i found a solution with the format in front like this
i tried 'Me.lblTotal.Caption = Nz(DSum("CashTotal", "dbCash", "Format[Currency]"), 0) and was toying around with it, however, your solution did indeed work and im greatful for that, thank you!
 
me.label1.Caption = FormatCurrency(Nz(DSum("CashTotal", "dbCash"), 0))
 
A label can be simulated with a textbox, providing a ControlSource which can be a DLookup expression.

BTW Textboxes etc have have a Controls Collection which connects them to their Label. This can be useful if you are working through a group of text boxes and need to reference their labels.
 

Users who are viewing this thread

Back
Top Bottom