If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Visual Basic > Add comma's on AfterUpdate

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-29-11, 11:29
hsiddique hsiddique is offline
Registered User
 
Join Date: Dec 2011
Posts: 3
Add comma's on AfterUpdate

Hi,

I have 4 textboxes that will contain sq ft values. I want to set so that the user can enter for e.g. 12345, Once the next textbox is selected, I want to automatically change the value to 12,345.

I've tried the following
Code:
Public Sub CheckArea(Area As Integer)

  If Len(Area) = 7 Then
        Area = Left(Area, 1) & "," & Mid(Area, 4) & "," & Right(Area, 3)
    ElseIf Len(Area) = 6 Then
        new_value = Left(Area, 3) & "," & Right(Area, 3)
    ElseIf Len(Area) = 5 Then
        new_value = Left(Area, 2) & "," & Right(Area, 3)
  End If


End Sub
Private Sub txtExistingSpace_AfterUpdate()
        Call CheckArea(frmCityDev.txtExistingSpace.Text)
End Sub
But when I test it i get an Overflow error, am i on the right track or is there an easier way.

Thanks
Reply With Quote
  #2 (permalink)  
Old 04-24-12, 04:51
ieuan ieuan is offline
Registered User
 
Join Date: Apr 2012
Posts: 28
No, you are not on the right track. Use the Format function instead.

Private Sub txtExistingSpace_AfterUpdate()
txtExistingSpace = Format$(txtExistingSpace,"#,##0")
End Sub

*Or if you are using MS Access forms, you would not need to write a code. Just select the textbox, and in the Property Sheet, select Format and choose the correct formatting from the dropdown list (currency, standard, general number, dates, etc.).
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On