Results 1 to 7 of 7
  1. #1
    Preston.Borchelt is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    3

    Access String Compairison

    I have a weird bug in my problem when trying to check and format of a sting in my code.



    In my program I allow the user to define how their job numbers should be formatted when entering. This has worked for almost 16 years and now my client has found this bug.

    user defines job number format as: "000000-000"
    user enters job number as: "990002-002"

    After I run this command:
    Me![ClientNumber] = Format(Me![ClientNumber], strFormatJobNumber)

    Me![ClientNumber] = 001848-891

    For some reason the format command has a bug that only has an issue when the starting two values are a multiple of "3". for example: "33", "66", "99".

    If my end user enters: "990002002", the format statement works and the out come is "990002-002"

    I am trying to come up with another way to do this comparison, but cannot think of a way to check and make sure the job number is formatted correctly.

    Any help would be appreciated.

    Thanks,
    Preston

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,601
    You mean when user enters value with a hyphen, the entry is wrong? Just tested that and see it happening. It is not your program, has to do with Format function and maybe also the hyphen. I tested with + in place of the hyphen and that works.

    I would set input mask property instead of using formatting.

    This client allows staff to individually structure job number?
    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
    dreday's Avatar
    dreday is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    58
    You can create a function that checks each character

    Function formatcheck(byval cnum as string) as boolean

    dim i as integer
    i = 1

    Do while i < 10
    dim testchar as string
    testchar = mid(cnum,i,1)
    if i<>7 then
    if not(asc(testchar) between 48 and 57) then 'tests to see if the character is 0 to 9 via ascii value
    return false
    end if
    else
    if testchar <> "-" then 'makes sure hyphen is 7th character
    return false
    end if
    Loop

    return true

    end function

  4. #4
    Preston.Borchelt is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    3
    That is correct, but only when the number they are entering starts with "33", "66", and "99".

    No the client doesn't allow the staff to structure job numbers. This feature is there because I have many clients using this software and not all of them structure their job numbers the same.

    Input masks would be a fix if this was not customizable per client using the system.

  5. #5
    Preston.Borchelt is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    3
    Quote Originally Posted by dreday View Post
    You can create a function that checks each character

    Function formatcheck(byval cnum as string) as boolean

    dim i as integer
    i = 1

    Do while i < 10
    dim testchar as string
    testchar = mid(cnum,i,1)
    if i<>7 then
    if not(asc(testchar) between 48 and 57) then
    return false
    end if
    else
    if testchar <> "-" then
    return false
    end if
    Loop

    return true

    end function
    This is what I was thinking of as well, but was curious if there was something already built into access.

    Here is what I came up with:

    strFormatJobNumber = "######-###"
    If Not Me![ClientNumber] like strFormatJobNumber Then
    Me![ClientNumber] = Format(Me![ClientNumber], strFormatJobNumber)
    End If

    Quick testing seems to work correctly. Just have to retrain the end users when setting up data files.

  6. #6
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Quote Originally Posted by Preston.Borchelt View Post

    Input masks would be a fix if this was not customizable per client using the system.
    As long as you don't set them at table level and just at form level, they are totally customizable via code so you could do this.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,601
    I tested in the VBA immediate window and it did not work. It returned the same value as the other pattern, only with leading zeros dropped.

    What you are trying to do is force users to enter value according a defined pattern. This is input masking.
    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. Create dynamic connection string to Access
    By janwane in forum Access
    Replies: 2
    Last Post: 10-07-2011, 06:56 AM
  2. Can access take one text string and split it into two?
    By hobsondm01 in forum Database Design
    Replies: 2
    Last Post: 06-09-2011, 09:09 AM
  3. Access front end for parsing xml string
    By raghu_nandan1 in forum Programming
    Replies: 0
    Last Post: 04-21-2011, 07:58 PM
  4. Replace a string/text in ms-access db
    By anziga in forum Queries
    Replies: 4
    Last Post: 12-31-2010, 06:40 PM
  5. Import XML String into Access table
    By chrisjohns in forum Programming
    Replies: 0
    Last Post: 04-16-2009, 01:47 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