Displaying currency fields from Access to vb text box

vbnewb

New member
Joined
May 9, 2003
Messages
2
Hey all,

Ive been lurking for awhile and have learned a lot from just reading the posts here.

Now I have a question that I cant find the answer to. I hope Im posting in the right forum. If not, I apologize.

I have several text boxes on a form that are binded to fields in an access database. I cant get the fields that are formatted as currency in Access to display as currency in the text box. :confused:

Ive tried using FormatCurrency() around the binding for the text box but I get an error.

Since all the data binding is done in the property setting for the text box, the load event passing the database to the binding is the only code I really have to show:

Code:
Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        daStocks.Fill(DsStocks1)
        currManager = Me.BindingContext(DsStocks1, "Stocks")
End Sub

Im sure the answer is right under my nose.

Any help would be appreciated.

Thanks!!

Heather
 
I havent used the BindingContext as yet, I assign the dataset fields to the textboxes using my own code. I therefore use the format() method to display the currency symbol.
 
After I let it sit for awhile, I was able to come back and figure out how I could solve my problem.

Heres the code I ended up using to pass the values to a variable then format the variable to be passed back to the text box as currency. Works like a charm.

Code:
Private Sub curformat()
        Dim pprice As Decimal
        Dim scommission As Decimal
        Dim sprice As Decimal
        Dim pcommission As Decimal
        Dim gainloss As Decimal
      
       store value from text boxes in a variable
        pprice = txtPurPrice.Text
        scommission = txtSalesCommission.Text
        sprice = txtSale.Text
        pcommission = txtPurCommission.Text
        gainloss = lblCapGL.Text
        
       pass formatted value back to text box to display as currency
        txtPurPrice.Text = FormatCurrency(pprice)
        txtSalesCommission.Text = FormatCurrency(scommission)
        txtPurCommission.Text = FormatCurrency(pcommission)
        txtSale.Text = FormatCurrency(sprice)
        lblCapGL.Text = FormatCurrency(gainloss)
    End Sub

:D
 
You can use the Format and Parse events of your DataBindings collection to automatically format data.

Heres a code snippet to setup the binding. Check the help on how to code the Format and Parse events - they contain sample code to convert numbers back and forth so that you can type "1,234,999" and it will convert it to "1234999" so that the database wont cause problems.

textBox1.DataBindings(0).Parse += new ConvertEventHandler(CurrencyStringToDecimal_Nullable);

Thats C# syntax. For VB, I think youll want to use AddHandler but I dont know the syntax. Check the help for the Format or Parse event and all will be revealed :)

-Nerseus
 
Back
Top