|
-
Feb 12th, 2004, 03:13 PM
#1
Thread Starter
Junior Member
Formatting a textbox for currency
I am taking data from a database and loading it into a form. The form and the database are connect using a Data Controller. I need one of the textboxes that is displaying the data to show the data as currancy. I know how to make a textbox display a variable as currancy, but I can't get any variation of this to work.
Thanks,
bsac4
New to VB
-
Feb 12th, 2004, 03:16 PM
#2
Re: Formatting a textbox for currency
Originally posted by bsac4
but I can't get any variation of this to work.
What variation are you after?
-
Feb 12th, 2004, 03:23 PM
#3
Thread Starter
Junior Member
I just want the textbox to show the data being loaded into it from the database as currency. So that it would show up as $23.00 instead of 23.
Thanks!
bsac4
-
Feb 12th, 2004, 03:28 PM
#4
You mentioned that you can do it with a Variable. In this case, replace the Variable with the Control .Value. Eg.
VB Code:
'your code that is loading the "other" TextBox's
Text1.Text = FormatCurrency([b]rs.(FieldName).Value[/b])
Where (in this case) rs is a RecordSet.
Bruce.
-
Feb 12th, 2004, 03:55 PM
#5
Thread Starter
Junior Member
On one of my other forms, I do have the connection to the database coded, but on this form, I was trying to give the user a quick way to look through the files on the database (since this is a very small database). So I just used the Data Controller, which I added to the bottom of the form. Then in the properties window told it what databasae to connect to and which table. So now I am not sure how to tell it which rs. I tried
txtCostPerUnit.Text = FormatCurrency(Data1.CostPerUnit.Value)
Where Data1 is my Data Controller name and CostPerUnit is the field in the table that I want formatted, but it didn't work.
I know that I am probably just being slow here. Thanks for your patience!
bsac4
-
Feb 12th, 2004, 04:12 PM
#6
Hey no problem 
What didn't it do? ie Not Format properly or didn't display any value?
Bruce.
-
Feb 12th, 2004, 04:15 PM
#7
I never use the Data control so I don't know if txtCostPerUnit.Text = FormatCurrency(Data1.CostPerUnit.Value) is valid, but unless Data1 is on the same form where that code is, you need to do
txtCostPerUnit.Text = FormatCurrency(frmOther.Data1.CostPerUnit.Value)
where frmOther is the name of the form where the Data1 control resides.
-
Feb 12th, 2004, 04:15 PM
#8
If it didn't dispaly any data, my guess is that you have ALL the (display) code in the Form_Load Event. If so, the Data Controller may not have extracted the Table data quick enough.
Try putting the 'txtCostPerUnit.Text = FormatCurrency(Data1.CostPerUnit.Value)' code under a CommandButton (or (still in the Form_Load) use 'DoEvents' prior to the TextBox's loading).
Bruce.
Last edited by Bruce Fox; Feb 12th, 2004 at 04:19 PM.
-
Feb 12th, 2004, 04:17 PM
#9
Originally posted by MartinLiss
but unless Data1 is on the same form where that code is
He did. Its on the botom of the Form. 
Bruce.
-
Feb 12th, 2004, 05:05 PM
#10
Thread Starter
Junior Member
I got a compile error:
Method or data member not found.
bsac4
-
Feb 12th, 2004, 05:10 PM
#11
Originally posted by bsac4
I got a compile error:
Method or data member not found.
bsac4
What line of code?
-
Feb 12th, 2004, 05:12 PM
#12
Thread Starter
Junior Member
txtCostPerUnit.Text = FormatCurrency(Data1.CostPerUnit.Value)
It highlights CostPerUnit as the problem.
bsac4
-
Feb 12th, 2004, 05:19 PM
#13
The Data Control may not have a .Value property.
What does the 'intelisense' (in the IDE) list give you when you type "Data1.CostPerUnit" (directly) followed by a "."?
-
Feb 12th, 2004, 05:30 PM
#14
Thread Starter
Junior Member
Actually, I just realized that CostPerUnit isn't an option in the intelisense list and no list comes up when I add a . after it. I removed CostPerUnit and left it with Data1.
The options didn't show any field names or Value. It does have Database, DatabaseName, and RecordSource as . options for Data1 but I am not sure which would be a good starting point or how I should call it out.
Thanks,
bsac4
-
Feb 12th, 2004, 05:47 PM
#15
I am just knocking something up (in VBA) using Adodc1 
In the mean time there was a tutorial posted here using the Data Control.
-
Feb 12th, 2004, 06:00 PM
#16
Does this help:
VB Code:
txtCostPerUnit.Text = FormatCurrency(Data1.Recordset.Fields("CostPerUnit").Value)
Edit:
here is the use the of the (successfully tested) example above , like:
VB Code:
Option Explicit
Private Sub Data1_Reposition()
txtCostPerUnit.Text = FormatCurrency(Data1.Recordset.Fields("CostPerUnit").Value)
End Sub
So that everytime you move thru the RecordSet the data will be Formated in txtCostPerUnit (even upon Load).
Bruce.
Last edited by Bruce Fox; Feb 12th, 2004 at 07:59 PM.
-
Feb 16th, 2004, 12:57 AM
#17
Thread Starter
Junior Member
You are THE GREATEST!!!! Thanks. It worked perfectly!
bsac4
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|