Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms / March 2007

Tip: Looking for answers? Try searching our database.

Type 1k for 1000, 1m for 1000000

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jackson - 22 Mar 2007 14:01 GMT
Hi,

I've got a form where trades are booked, the quantity field is bound to a
table that the user is updating, and the underlying table field is a number
format (obviously for trade quantity). What I'm trying to work out is if I
can in someway have this field on the form handle typing 1K and then updating
to 1000 for example. The problem obviously is that this form text box is
bound to a numeric field that won't accept text, so if I write code into the
Before Update event to convert Ks and Ms to numbers, access says 'The value
you entered isn't valid for this field.'

A longer way round is for me to make the field unbound and code it in, I
already run an update query so this is feasible, just seems there would be
someway to do this whilst leaving the field bound as a numeric format....any
ideas?

Cheers.
Allen Browne - 22 Mar 2007 14:10 GMT
Try the KeyPress event of the control.

If the character is K or k, set KeyCode to 0, and assign the Text followed
by 000 as the Value of the control.

Use SelStart and SelLen to understand where the cursor is in the Text, and
to reposition the cursor again (if it was not at the end of the Text.)

You can do this with the Text property, because it has not become the Value
yet.

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> Hi,
>
[quoted text clipped - 16 lines]
> format....any
> ideas?
Alec M1BNK - 22 Mar 2007 15:49 GMT
How's about this

You hide the box, put an unbound textbox on the form, and use an afterupdate
event thus

Private Sub txtNumBox_AfterUpdate()
   Dim intCharPos as Integer
   If IsNull(txtNumBox) Then Exit Sub
   intCharPos = instr(tNumbox, "k")                     'Look for a k
   if intCharPos > 1 then
       intChatPos=intCharPos-1                             'Trim off the k
       'transfer 1000 * value of the digits to the left of the k
       'to the hidden number box
       numHiddenBox=VAL(Left$(txtNumBox,intCharPos))*1000
       Exit Sub
   End If
   intCharPos = instr(tNumbox, "m")                     'Look for a m
   if intCharPos > 1 then
       intChatPos=intCharPos-1                             'Trim off the m
       'transfer 1000000 * value of the digits to the left of the m
       'to the hidden number box
       numHiddenBox=VAL(Left$(txtNumBox,intCharPos))*1000000
       Exit Sub
   End If
   'if no k and no m then transfer value of the digits
   'to the hidden number box
    numHiddenBox=VAL(Left$(txtNumBox,intCharPos))
End Sub

> Hi,
>
[quoted text clipped - 13 lines]
>
> Cheers.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.