Results 1 to 4 of 4
  1. #1
    GSBones is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    2

    Trying to make a Default Value for the beginning of a field.

    I created a database to track purchase orders, and have a field called 'DocNbr' to hold the invoice number. It is not a key field, and don't want it to be, as sometimes there can be duplicates.



    The field is always 13 characters in length, 99% of the time the first 5 characters are constant, and the remaining 8 are a combination of date and sequence number that must be entered manually.

    What I'm looking for it to do, is when you tab into that field, the first 5 characters are auto populated, then you type in the remaining 8. (Ideally, after those 8 are entered it goes automatically to the next field without hitting Tab.) There are occasions when those first 5 need to change, so I would like the opportunity to replace them when entering data in that field.

    I can get close to what I want with the Input Mask, and Default Vault, as it will populate the field with those 5 characters, but when I type the remaining 8, it overwrites the first 5. Unless I use the cursor to position it after those first 5.

    Hope this makes sense.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Can use code to position the cursor at the end of the string. Example for a combobox:

    Private Sub cbxSample_Enter()
    If Not IsNull(Me.cbxSample) Then Me.cbxSample.SelStart = Len(Me.cbxSample)
    Me.cbxSample.Dropdown
    End Sub

    For a textbox just don't use the Dropdown code.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    GSBones is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    2
    Thanks for the help.
    That code did help in positioning the cursor correctly. However when it stored the field in the record, it only stored what was typed, not the first 5 default characters.
    In the end I got tired of messing with it and created 3 separate fields that make up the sections of the Invoice number. It ended up doing what I was after anyway.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    The input mask would have to be set to save the value with the literal parts. Review Access Help about input mask for specifics.

    But your solution is also good.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 4
    Last Post: 01-15-2014, 08:46 PM
  2. Replies: 3
    Last Post: 01-08-2013, 02:41 PM
  3. Replies: 5
    Last Post: 10-17-2011, 02:53 PM
  4. Find command default make it Any part of field
    By techexpressinc in forum Forms
    Replies: 0
    Last Post: 03-15-2011, 07:34 AM
  5. Replies: 1
    Last Post: 12-09-2005, 09:27 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