Hi,
Is it possible to format a field in a userform, for example to currency?
If so, how?
Thanks,
Hi,
Is it possible to format a field in a userform, for example to currency?
If so, how?
Thanks,
Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
But thats nothing compared to the horrors that lurk beneath The Trap Door.
As you've probably noticed there is no property for a textbox to change the formatting. That said, you can do your formatting via VBA. You can use the FormatCurrency function (see Help) to format your variable's value so it displays correctly in the UserForm textbox.
-Randy Shea
I'm a programmer, but I'm also pro-grammar!
If your issue is resolved, please use Thread Tools to mark your thread as Solved!
PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003
Or just Format which gives you access to any number of formats,
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber
Hi Randy,Originally Posted by CreganTur
To be honest, i'm not too bothered about it looking right in the textbox, although it would be nice. I'm more concerned about it correctly adding the data into Access....
I've tried this :-
'Recordset("Original_Premium") = txtOPrem.Value = Format("Currency")'
The values show on the Access table as ?0.00 (Access table field is defined as currency).
Help!
Thanks,
Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
But thats nothing compared to the horrors that lurk beneath The Trap Door.
If you format it correctly in the textbox, and use txtOPrem.Text, as a string it will be correct as passed to Access.
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber
Sorry, i'm having a brain blank moment, can you elaborate a little more please.Originally Posted by xld
Cheers,
Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
But thats nothing compared to the horrors that lurk beneath The Trap Door.
I'd use the FormatCurrency function and explicitly declare the number of decimal places:
[vba]Recordset("Original_Premium") = txtOPrem.Value = FormatCurrency("Currency",2)'[/vba]
-Randy Shea
I'm a programmer, but I'm also pro-grammar!
If your issue is resolved, please use Thread Tools to mark your thread as Solved!
PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003
Hmmm.... I'm getting a compile error with that one, Sub or Function not defined.Originally Posted by CreganTur
Excel '97 problem?
Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
But thats nothing compared to the horrors that lurk beneath The Trap Door.
Load the textbox and format
[vba]
txtOPrem.Text = Format(123,"?#,##0.00")
[/vba]
then load the Recordest from that
[vba]
Recordset("Original_Premium") = txtOPrem.Text
[/vba]
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber
OK, I've added this into the initalise routine, i now shows ?123.00 in txtOPrem. Now, if i enter into this field and overwrite the entered data it looses the format.... am i missing something?Originally Posted by xld
Thanks,
Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
But thats nothing compared to the horrors that lurk beneath The Trap Door.
The formatting belongs to the variable's value, not the textbox. The textbox has no formatting of its own. You can add in an AfterUpdate event for the textbox that will reformat data entered into it to FormatCurrency.Now, if i enter into this field and overwrite the entered data it looses the format.... am i missing something?
-Randy Shea
I'm a programmer, but I'm also pro-grammar!
If your issue is resolved, please use Thread Tools to mark your thread as Solved!
PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003
I'm still a little confused about the afterupdate event....
[VBA]Private Sub txtIPrem_AfterUpdate()
txtIPrem.Text = Format(123, "?#,##0.00")
End Sub[/VBA]
OR
[VBA]Private Sub txtIPrem_AfterUpdate()
txtIPrem.Text = Format("?#,##0.00")
End Sub
[/VBA]
Both don't give the result i'm looking for.
In the first instance it enters ?#,##0.00 into the field
In the second I get ?123.00.
Any suggestions? (FormatCurrency doesn't appear to work on Excel '97)
Thanks,
Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
But thats nothing compared to the horrors that lurk beneath The Trap Door.
[vba]
Private Sub txtIPrem_AfterUpdate()
txtIPrem.Text = Format(txtIPrem.Text, "?#,##0.00")
End Sub
[/vba]
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber
That works nicely thanks xld.Originally Posted by xld
Once other quick question...
Formatting percentages.
If I use "##%" i get 1000% when the user enters 10 in the field.
How can i get it to show correctly as 10%?
Thanks,
Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
But thats nothing compared to the horrors that lurk beneath The Trap Door.
Hi Again,
The currency fields now format correctly, however when i try and send the data into Access i'm still getting a 'Type Mismatch Error'.
The fields in Access are set as a Data Type of 'Currency'.
If I change them back to 'Text' I don't get an error.
Any suggestions?
Thanks,
Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
But thats nothing compared to the horrors that lurk beneath The Trap Door.
Just use 0%
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber
You are probably trying to load a string value, complete with ? and , symbols into a numeric field.Originally Posted by phendrena
You could strip the garbage before loading it, like so
[vba]
Function ValidAmount(ByVal amt As String) As Double
Dim RegEx As Object
Set RegEx = CreateObject("VBScript.RegExp")
RegEx.Pattern = "[?,]"
ValidAmount = RegEx.Replace(amt, "")
Set RegEx = Nothing
End Function
[/vba]
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber