473,383 Members | 1,896 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Textbox format question

Good afternoon.

I have a "Fixed/2" format applied to a textbox on its property sheet. When I
type data in the textbox, it is formatted correctly. But when I update the
value programatically by setting the "value" property, the text does not
format.

I can get around this of course by using the VBA format() command. But is
there any way I could update the value in code and have it display according
to the format that is specified on the control's property sheet?

Thanks
-Mark
Sep 20 '07 #1
9 9275
On Thu, 20 Sep 2007 16:18:50 -0700, "Mark G." <an*******@hotmail.com>
wrote:

The Format function IS the way to do that.
-Tom.

>Good afternoon.

I have a "Fixed/2" format applied to a textbox on its property sheet. When I
type data in the textbox, it is formatted correctly. But when I update the
value programatically by setting the "value" property, the text does not
format.

I can get around this of course by using the VBA format() command. But is
there any way I could update the value in code and have it display according
to the format that is specified on the control's property sheet?

Thanks
-Mark
Sep 21 '07 #2
"Tom van Stiphout" <no*************@cox.netwrote:
>
The Format function IS the way to do that.
So the format applied via the textbox property sheet is only for user-typed
input? And there is no (reasonable) way to invoke that format
programatically?
Sep 21 '07 #3
Mark, I take it that this is an *unbound* text box?

If so, Access cannot determine the data type by looking at the field it is
bound do. So when you assign a value programmatically, Access may not
recognise as numeric.

If that's what is happening, you may be able to solve the problem by
rounding and/or typecasting, e.g.:
Me.Text0 = CDbl(Round(SomeNumber, 2))

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Mark G." <an*******@hotmail.comwrote in message
news:11***************@bubbleator.drizzle.com...
Good afternoon.

I have a "Fixed/2" format applied to a textbox on its property sheet. When
I type data in the textbox, it is formatted correctly. But when I update
the value programatically by setting the "value" property, the text does
not format.

I can get around this of course by using the VBA format() command. But is
there any way I could update the value in code and have it display
according to the format that is specified on the control's property sheet?

Thanks
-Mark
Sep 21 '07 #4
On Thu, 20 Sep 2007 19:25:25 -0700, "Mark G." <an*******@hotmail.com>
wrote:

Correct. You would have to write the code yourself.

This is similar to the realization: if I programmatically change the
value of a control, the Change event does not occur.

-Tom.
>"Tom van Stiphout" <no*************@cox.netwrote:
>>
The Format function IS the way to do that.

So the format applied via the textbox property sheet is only for user-typed
input? And there is no (reasonable) way to invoke that format
programatically?
Sep 21 '07 #5
On Sep 20, 7:18 pm, "Mark G." <anon40...@hotmail.comwrote:
Good afternoon.

I have a "Fixed/2" format applied to a textbox on its property sheet. When I
type data in the textbox, it is formatted correctly. But when I update the
value programatically by setting the "value" property, the text does not
format.

I can get around this of course by using the VBA format() command. But is
there any way I could update the value in code and have it display according
to the format that is specified on the control's property sheet?

Thanks
-Mark
The following brute force ugly HACK might help:

....
Dim varNewValue As Variant
Dim strIn As String

varNewValue = 24.3333

If MyTextbox.Format = "Fixed" Then
If MyTextbox.DecimalPlaces = 255 Then
'Auto
strIn = "0.00"
Else
strIn = "#0." & String(MyTextbox.DecimalPlaces, "0")
End If
MyTextbox.Value = Left(CStr(Format(Round(varNewValue,
MyTextbox.DecimalPlaces), strIn)), InStr(CStr(varNewValue), ".") +
MyTextbox.DecimalPlaces - Abs(MyTextbox.DecimalPlaces = 0))
Else
MyTextbox.Value = Format(varNewValue, MyTextbox.Format)
End If
....

MyTextbox.Format MyTextbox.DecimalPlaces Result
Fixed Auto 24.33
Fixed 0 24
Fixed 1 24.3
Fixed 2 24.33
Fixed 3 24.333
Fixed 4 24.3333
Fixed 5 24.33330
Fixed 6 24.333300
Currency Auto $24.33
Short Time Auto 07:59 (almost a third of a day)
Long Time Auto 7:59:57 AM
General Date Auto 1/23/1900 7:59:57 AM

James A. Fortune
CD********@FortuneJames.com

Sep 21 '07 #6
<CD********@FortuneJames.comwrote:
>
The following brute force ugly HACK might help:
Suddenly the VBA format() function looks like a very attractive solution.
:-)
Sep 21 '07 #7

"Tom van Stiphout" <no*************@cox.netwrote:
On Thu, 20 Sep 2007 19:25:25 -0700, "Mark G." <an*******@hotmail.com>

This is similar to the realization: if I programmatically change the
value of a control, the Change event does not occur.
Ah. So the change() event occurs when the user enters text in the textbox,
and this causes the format specified on the property sheet to be applied to
the user's input?
Sep 21 '07 #8
On Fri, 21 Sep 2007 08:56:52 -0700, "Mark G." <an*******@hotmail.com>
wrote:

No. This was just an analogous observation.
-Tom.
>
"Tom van Stiphout" <no*************@cox.netwrote:
>On Thu, 20 Sep 2007 19:25:25 -0700, "Mark G." <an*******@hotmail.com>

This is similar to the realization: if I programmatically change the
value of a control, the Change event does not occur.

Ah. So the change() event occurs when the user enters text in the textbox,
and this causes the format specified on the property sheet to be applied to
the user's input?
Sep 22 '07 #9
"Allen Browne" <Al*********@SeeSig.Invalidwrote:
Mark, I take it that this is an *unbound* text box?
Correct. I was wondering whether there is any way to have the property
sheet format applied to text that is inserted programatically, but
apparently
there is not. So I am using the VBA format() function.

-Mark
Sep 22 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Rookie | last post by:
I need to display several columns of numbers in a textbox. I wish to display the columns with the decimal point position aligned vertically. I have found that the # digit placeholders do not...
1
by: Steve B. | last post by:
An incorrect date and time format appears in the Textbox when I _Leave(..) the date TB and focus on another TB for the same Datagrid index (1/8/05 12:00:00 AM vice 1/8/05). I have an MS-Access...
2
by: pmclinn | last post by:
I have a textbox named "mydate" and I want to add an "onblur" event to it that will format the text in this format: dd-MMM-yy the data entry people use this format in the text box: dd/mm/yy...
4
by: Fred Nelson | last post by:
Hi: I'm very new to vb.net and I apologize if this question should have been found in the documentation however I don't understand the documentation. I have a textbox on a vb.net web form that...
1
by: Agnes | last post by:
In my Textbox, I can set input mask by using keypressevent. E.g If Me.txtID.length = 3 then Me.txtId.appendtext("-") Now, in DataGridcolumns' textbox, How can I do the simliar approach ? Thanks
13
by: Roy | last post by:
Hi all, I'm creating a project that should always use this date format when displays the dates or create dates. The back end database is a SQL Server and I like to know what is the logical way...
2
by: Walter | last post by:
I have a GridView using Template columns. In my EditItemTemplate I am using CompareValidators to check data types. When validation fails, I would like to change the border of the textbox in...
1
by: Frank | last post by:
Hello, I am working with an editable column in a datagrid for the first time. I am using VisualStudio.Net 2003 on the ASP 1.1 framework. I am having trouble with setting the width of a text...
8
Alireza355
by: Alireza355 | last post by:
Deal all, I have a textbox that I want to apply some formatting to the text: I know that if the textbox contains only numbers, by selecting "Standard" format, I can have the thousands...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.