hi DS
What you need to do on the form is this.
1. Create a textbox and make the backstyle and borderstyle transparent. also make the forecolor white. This will be named txtHidden.
2. Create a label and make it look like a textbox by setting backcolor to white and specialeffect to sunken. This is named lblDisplay.
2a. Make both TextAlign to Right
3. Make both the same width but make the height of txtHidden about 1mm.
4. Make the tops of both the same and send txtHidden to back of zorder.
Here's the code behind the form. you may need to set the various event properties in the form to EventProcedure.
Option Compare Database
Option Explicit
Private Sub Form_Load()
'set initial value...you set this as required
'you may have an initial value you wish to use
lblDisplay.Caption = Format(0, "$0.00")
End Sub
Private Sub txtHidden_Change()
Dim strX As String
'get length of hidden boxes text
'and adjust output accordingly
Select Case Len(Trim(txtHidden.Text))
Case 0
strX = "0"
Case 1
strX = ".0" & txtHidden.Text
Case 2
strX = "." & txtHidden.Text
Case Else
strX = Left(txtHidden.Text, Len(Trim(txtHidden.Text)) - 2) & "." & Right(txtHidden.Text, 2)
End Select
'display formatted result in label
lblDisplay.Caption = Format(strX, "$0.00")
End Sub
Private Sub txtHidden_GotFocus()
'set cursor location
txtHidden.SelStart = Len(Trim(txtHidden.Text))
End Sub
Private Sub txtHidden_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
'****************************
'ALLOW THESE INPUT CHARACTERS
'****************************
'8=backspace
'9=tab
'46=delete
'37=left arrow/39=right arrow
'48 to 57=numeric digits
Case 8, 9, 46, 37, 39, 48 To 57
'do nothing
Case Else
'reject character and exit
KeyCode = 0
Exit Sub
End Select
End Sub
If set up right you can just see the cursor of txtHidden when it receives focus. you can use this as a guide to editing the output in lblDisplay. Also you may wish to allow more characters to be entered in txtHidden. These can be added to the Select Case structure Have a play about with it and let me know how you get on.
kind regards
steve