Solved Sql outcome as a label? (1 Viewer)

mamradzelvy

Member
Local time
Today, 12:01
Joined
Apr 14, 2020
Messages
145
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?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:01
Joined
May 7, 2009
Messages
19,169
add code to the Form's Load Event.

private sub form_load()
me.label1.Caption = Nz(DSum("CashTotal", "dbCash"), 0)
end sub
 

mamradzelvy

Member
Local time
Today, 12:01
Joined
Apr 14, 2020
Messages
145
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?
 

cheekybuddha

AWF VIP
Local time
Today, 11:01
Joined
Jul 21, 2014
Messages
2,237
Did you search?

What have you tried?

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

mamradzelvy

Member
Local time
Today, 12:01
Joined
Apr 14, 2020
Messages
145
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!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:01
Joined
May 7, 2009
Messages
19,169
me.label1.Caption = FormatCurrency(Nz(DSum("CashTotal", "dbCash"), 0))
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 22:01
Joined
Jan 20, 2009
Messages
12,849
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

Top Bottom