PDA

Click to See Complete Forum and Search --> : Data formatting


turfbult
Aug 23rd, 2000, 01:49 PM
Hi all,

I'm still having trouble formatting my data correctly.

I have a access database with a numeric field "amount" which is set as number,standard,2 decimal places. I have a form with a textbox "amount" and the dataformat is set to number,2 decimals and 1000 seperator.

Firstly I want the form to display 0.00 when first loaded - I tried to set txtamount.text = 0.00, but it still just shows 0.

Secondly I want to insert exactly what the user enters into txtamount into my table. What happens now is that the user types in 5.56 - I then debug my code and in my insert statement I can see that it looks fine ie. "insert into client values 5.56", but when I go and read that record again it brings it back as rounded ie. client!amount = 6.
I tried using ccur(trim(txtamount.text)), but this still does not work.

And then lastly... when the user enters the amount on the form I want him to overwrite whatever is in txtamount.text and not "add-on" to it. ie. when the form loads it displays 0 in txtamount.txt, now I want the user enters 49 - what happens is that it just pust the 49 in front of the zero so it becomes 490. I also want an input mask so that whatever the user enters goes in BEFORE the decimal until the fullstop is pressed and then the user can input the decimals (hope this makes sense!!!??) How can I fix this without having to backspace on the zero and then typing what I want??

Sorry for the "long one", but if you can help me it'll be MUCH appreciated!!

Thanks.

hemsoft
Aug 23rd, 2000, 02:10 PM
You say you have a numeric field, standard, 2 - I think you should change standard to fixed, forcing Access to always display 2 decimals when you view the data.

In your Form_Load() event, add code to set your textbox to "0.00":

Private Sub Form_Load()
Me.Text1.Text = "0.00"
End Sub

Regarding your insert statement, use:
INSERT INTO <table> VALUES(<num>) for numbers, and
INSERT INTO <table> VALUES('<string>') for strings.

Are you using ADO, and if so, why not share the code with us, maybe I'll be able to spot the error more easily...

Last, in order to let the user replace what was previously typed in your textbox, you should look into writing code in your control's _GotFocus() event:

Private Sub Text1_GotFocus()
Me.Text1.SelStart = 0
Me.Text1.SelLength = Len(Me.Text1.Text)
End Sub

Best regards
Franz Hemmer

JHausmann
Aug 23rd, 2000, 02:54 PM
For your second part, try using the format command to set the value:

txtAmount.Text = Format(client!amount, "$###,###,###,###.00")

turfbult
Aug 23rd, 2000, 03:07 PM
Franz,

All the other tips you gave me work fine, but my figures still get rounded!!

Franz,

This is just a small part of the insert statement which I execute - txtindVehicle is a numeric - I also set the number to fixed in access!! My figures STILL get rounded - like I said if I debug.print ssql then I can see that txtindVehicle is something like 1.56, but when I go and viwe the table in access it shows as 2.00.

code:

public sub insert_client()

ssql = "insert into client values (" & txtindVehicle & ")

cnconnect.execute (ssql)

end sub


Thanks JHausmann - I'll give your reply a try staright away!!