Page 1 of 2 12 LastLast
Results 1 to 15 of 30
  1. #1
    bassplayer79 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2013
    Posts
    18

    Add letters to sequential numbers

    Hello everyone, this is my first post. I had a little programming background, but as of recently my boss is teaching me how to create Access and VB applications. Its been quite a learning experience!!


    Ok heres my issue. I created an application that generates tags for stock. I start the first number with 1111, when a button is pushed it creates a new tag with 1112 and so on. I need to add WA to the beginning of the numbers. I created a function for this, and here is the code:

    Public Function Generate_Number_Click()
    'Create Washer Serial Number
    Dim lngsnum As Long

    lngsnum = DMax("[WAS]", "table1")

    lngsnum = lngsnum + 1

    wastxt = "WA" & lngsnum

    End Function

    It clearly did now like when I added "WA", as I keep getting a mismatch error. I was hoping it would be that easy, but I guess not.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    "WA" is a string value and you cannot put it in a numerical field! Is "wastxt" a control on your form? To what type of field is it bound?

  3. #3
    bassplayer79 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2013
    Posts
    18
    Quote Originally Posted by RuralGuy View Post
    "WA" is a string value and you cannot put it in a numerical field! Is "wastxt" a control on your form? To what type of field is it bound?
    wastxt is the name of the text box i want to but the text (WA1111) in. From there it is dumped into a database along with other information to tie everything together

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Does the wastxt control have a ControlSource? If so, what is it? If it is a Field in the RecordSource of the form, what type of Field is it?

  5. #5
    bassplayer79 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2013
    Posts
    18
    Quote Originally Posted by RuralGuy View Post
    Does the wastxt control have a ControlSource? If so, what is it? If it is a Field in the RecordSource of the form, what type of Field is it?
    Yes it does have a control source, it is bound to the "WAS" field in the table1 table. The field type is text, long.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,896
    Access 2010 doesn't have a 'long' text field. There are Text and Memo. I think 2013 changed those to Short and Long Text.
    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.

  7. #7
    bassplayer79 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2013
    Posts
    18
    I want to make sure I didn't mislead you. If I remove "WA" &, everything works beautifully.

  8. #8
    bassplayer79 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2013
    Posts
    18
    Quote Originally Posted by June7 View Post
    Access 2010 doesn't have a 'long' text field. There are Text and Memo. I think 2013 changed those to Short and Long Text.
    Your right, its just text

  9. #9
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I strongly suspect your "WAS" field is numeric and not Text. Try doing this and see what you get:
    wastxt = "WA9999" '-- & lngsnum

  10. #10
    bassplayer79 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2013
    Posts
    18
    Quote Originally Posted by RuralGuy View Post
    I strongly suspect your "WAS" field is numeric and not Text. Try doing this and see what you get:
    wastxt = "WA9999" '-- & lngsnum
    Click image for larger version. 

Name:	table1.jpg 
Views:	22 
Size:	24.4 KB 
ID:	13698
    Heres a snapshot. It says text, but maybe Im missing something. I think you're missing something from your code, if I put that in, '-- & lngsnum would be commented out.

  11. #11
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Or even better would be:
    Me!WAS = "WA9999"
    ...which will bypass the control and write directly to the Field in the table.

  12. #12
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    That was the point, to just write text to the control. Thanks for the picture. It sure looks like a Text field to me. Now that we know it is a Text field you may wish to review the [ lngsnum = DMax("[WAS]", "table1") ] line since ASCII does not sort like numbers do.

  13. #13
    bassplayer79 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2013
    Posts
    18
    Quote Originally Posted by RuralGuy View Post
    That was the point, to just write text to the control. Thanks for the picture. It sure looks like a Text field to me. Now that we know it is a Text field you may wish to review the [ lngsnum = DMax("[WAS]", "table1") ] line since ASCII does not sort like numbers do.
    Do you have an suggestions, I was under the impression I could reuse this code for this purpose, but apparently not.

  14. #14
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Let's solve the "mismatch error" first. Any chance you could post the db? Removing any sensitive data of course. Compact and Repair and then ZIP it before posting. If not, we can still take shots at it.

  15. #15
    bassplayer79 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2013
    Posts
    18
    No I can post it, nothing sensitive, still in dev stage.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. mix of letters and numbers on the form
    By iscinar in forum Forms
    Replies: 15
    Last Post: 10-20-2013, 06:11 AM
  2. Sorting by Letters and then numbers with dashes
    By Analogkid in forum Queries
    Replies: 8
    Last Post: 04-29-2013, 05:05 PM
  3. IIF with numbers and letters
    By hzrdc2 in forum Queries
    Replies: 2
    Last Post: 03-28-2013, 07:29 AM
  4. Import Errors - Fields with Numbers and Letters
    By Eekers in forum Import/Export Data
    Replies: 5
    Last Post: 01-10-2012, 02:52 PM
  5. Removing all letters or all numbers from string
    By Hayley_sql in forum Programming
    Replies: 2
    Last Post: 09-16-2009, 02:01 AM

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