Results 1 to 15 of 15
  1. #1
    Paintballlovr is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2013
    Posts
    96

    Custom input mask

    I'm looking for some help in creating a custom input mask. I have a field on a form that is supposed to be a dollar amount entry. The field is formatted to currency with 2 decimal places, but the operator can type more than two to the right of the decimal, causing an inbalance when I compare this field to a total field. Is there a way to setup a custom input mask to allow any length (with + or - allowed) to the left of the decimal and only two to the right? It looks like the following input mask technically works, but it looks terrible as the operator enters data in the field.



    ##########.00;1

  2. #2
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    In the beforeupdate event for the field, you can truncate or round the entry to two decimals, or kick up an error message and make them fix it (in case they type .885 and meant .85).

  3. #3
    Paintballlovr is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2013
    Posts
    96
    Quote Originally Posted by Dal Jeanis View Post
    In the beforeupdate event for the field, you can truncate or round the entry to two decimals, or kick up an error message and make them fix it (in case they type .885 and meant .85).
    What would the beforeupdate code look like? I'm not good at generating code from scratch.

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Something like this, with TargetControl, in the code, being the actual name of the Control in question:

    Code:
    Private Sub TargetControl_BeforeUpdate(Cancel As Integer)
     If Len(Mid(Me.TargetControl, InStrRev(Me.TargetControl, ".") + 1)) > 2 Then
      MsgBox "You May Only Enter Two Digits After the Decimal Point!!!"
      Cancel = True
      TargetControl.SelStart = InStrRev(Me.TargetControl, ".") + 2
     End If
    End Sub

    This pops a warning message, then places the cursor at the point where the data should end, allowing the user to simply delete the extra digits by hitting and holding the Delete Key down.

    Linq ;0)>

  5. #5
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    linq's da bomb!

  6. #6
    Paintballlovr is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2013
    Posts
    96
    Quote Originally Posted by Missinglinq View Post
    Something like this, with TargetControl, in the code, being the actual name of the Control in question:

    Code:
    Private Sub TargetControl_BeforeUpdate(Cancel As Integer)
     If Len(Mid(Me.TargetControl, InStrRev(Me.TargetControl, ".") + 1)) > 2 Then
      MsgBox "You May Only Enter Two Digits After the Decimal Point!!!"
      Cancel = True
      TargetControl.SelStart = InStrRev(Me.TargetControl, ".") + 2
     End If
    End Sub

    This pops a warning message, then places the cursor at the point where the data should end, allowing the user to simply delete the extra digits by hitting and holding the Delete Key down.

    Linq ;0)>
    Do I need any formatting around my targetcontrol, like " or [ or anything? I tried simply replacing targetcontrol with the name of my control and it still allowed me to enter too many decimals and no message popped

    Private Sub CashPosted_BeforeUpdate(Cancel As Integer)
    If Len(Mid(Me.CashPosted, InStrRev(Me.CashPosted, ".") + 1)) > 2 Then
    MsgBox "You May Only Enter Two Digits After the Decimal Point!!!"
    Cancel = True
    CashPosted.SelStart = InStrRev(Me.CashPosted, ".") + 2
    End If
    End Sub

  7. #7
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Is the control in a form or a subform?

  8. #8
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    It will let you enter all the digits you want after the decimal, but when you go exit the Control the Messagebox will appear and the cursor will return to the appropriate position to delete the excess digits.

    The idea is to teach the users, saving them data entry time, once it sinks in that they can only two digits!

    Form or Subform shouldn't matter, in this scenario.

    Linq ;0)>

  9. #9
    Paintballlovr is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2013
    Posts
    96
    Quote Originally Posted by Dal Jeanis View Post
    Is the control in a form or a subform?
    It is on a subform

  10. #10
    Paintballlovr is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2013
    Posts
    96
    Quote Originally Posted by Missinglinq View Post
    It will let you enter all the digits you want after the decimal, but when you go exit the Control the Messagebox will appear and the cursor will return to the appropriate position to delete the excess digits.

    The idea is to teach the users, saving them data entry time, once it sinks in that they can only two digits!

    Form or Subform shouldn't matter, in this scenario.

    Linq ;0)>

    I must have something wrong in the code then because I could navigate away from the control either to another control on the subform or even to the main form and no message box came up.

  11. #11
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Well, let's see exactly what you're using!

    Linq ;0)>

  12. #12
    Paintballlovr is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2013
    Posts
    96
    Quote Originally Posted by Missinglinq View Post
    Well, let's see exactly what you're using!

    Linq ;0)>
    Private Sub CashPosted_BeforeUpdate(Cancel As Integer)
    If Len(Mid(Me.CashPosted, InStrRev(Me.CashPosted, ".") + 1)) > 2 Then
    MsgBox "You May Only Enter Two Digits After the Decimal Point!!!"
    Cancel = True
    CashPosted.SelStart = InStrRev(Me.CashPosted, ".") + 2
    End If
    End Sub

  13. #13
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Sorry, I forgot we were working with Currency! Some of the String Functions have a problem with Currency Fields, apparently due to the insertion of the monetary sign (such as $) and the addition of zero decimal places, if there are no decimals in the value. So, you need to remove the line
    Code:
    CashPosted.SelStart = InStrRev(Me.CashPosted, ".") + 2
    The user will just have to delete the extra decimals, so that only 2 are present, without any help.

    But running the code you gave, minus this line, still works as needed, for me; actually running your code, exactly as posted, stopped the updating, it just didn't place the cursor at the right place for deleting the extra digits without repositioning the cursor. If it still doesn't stop the updating of the Field, if more than two decimals are entered, you need to double check that the Control in question is actually spelled CashPosted. Barring that, you need to save the file in 2007 format, or earlier, ZIP it up and attach it to a post, for us to look at.

    Linq ;0)>

  14. #14
    Paintballlovr is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2013
    Posts
    96
    That took care of it. Thank you very much for all of your help!

  15. #15
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Glad we could help!

    Linq ;0)>

Please reply to this thread with any new information or opinions.

Similar Threads

  1. input mask
    By slimjen in forum Forms
    Replies: 7
    Last Post: 10-07-2013, 03:20 PM
  2. Input Mask
    By qbc in forum Access
    Replies: 2
    Last Post: 01-20-2012, 03:27 PM
  3. Custom (?) Date Input Mask
    By SeaTigr in forum Access
    Replies: 3
    Last Post: 11-07-2011, 02:40 PM
  4. Custom Data input mask or format?
    By RiverAnimal in forum Database Design
    Replies: 2
    Last Post: 12-06-2010, 09:58 AM
  5. custom mask
    By RedGoneWILD in forum Reports
    Replies: 2
    Last Post: 08-04-2010, 03:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums