Results 1 to 17 of 17

Thread: Formatting a textbox for currency

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2004
    Posts
    23

    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

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    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?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2004
    Posts
    23
    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

  4. #4
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    You mentioned that you can do it with a Variable. In this case, replace the Variable with the Control .Value. Eg.

    VB Code:
    1. 'your code that is loading the "other" TextBox's
    2.     Text1.Text = FormatCurrency([b]rs.(FieldName).Value[/b])

    Where (in this case) rs is a RecordSet.




    Bruce.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Feb 2004
    Posts
    23
    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

  6. #6
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Hey no problem


    What didn't it do? ie Not Format properly or didn't display any value?




    Bruce.

  7. #7
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    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.

  8. #8
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    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.

  9. #9
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    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.

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Feb 2004
    Posts
    23
    I got a compile error:

    Method or data member not found.

    bsac4

  11. #11

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Feb 2004
    Posts
    23
    txtCostPerUnit.Text = FormatCurrency(Data1.CostPerUnit.Value)

    It highlights CostPerUnit as the problem.
    bsac4

  13. #13
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    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 "."?

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Feb 2004
    Posts
    23
    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

  15. #15
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    I am just knocking something up (in VBA) using Adodc1

    In the mean time there was a tutorial posted here using the Data Control.

  16. #16
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Does this help:
    VB Code:
    1. txtCostPerUnit.Text = FormatCurrency(Data1.Recordset.Fields("CostPerUnit").Value)




    Edit:
    here is the use the of the (successfully tested) example above , like:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Data1_Reposition()
    4.     txtCostPerUnit.Text = FormatCurrency(Data1.Recordset.Fields("CostPerUnit").Value)
    5. 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.

  17. #17

    Thread Starter
    Junior Member
    Join Date
    Feb 2004
    Posts
    23
    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
  •  



Click Here to Expand Forum to Full Width