Results 1 to 15 of 15
  1. #1
    bburton is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2011
    Posts
    15

    End of Text Box - Replace Comma with Period

    I am building a report which will pull data from a form. There are a lot of fields that will be listed and separated by commas.



    Basically the box will look like this:
    = IIf(IsNull([1]),"",[1] & ", ") & IIf(IsNull([2]),"",[2] & ", ") & IIf(IsNull([3]),"",[3] & ", ")

    I need the last comma of that statement to be replaced with a period regardless of what data shows up and doesn't. What code would do this?

    Thank you for your help.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    = IIf(IsNull([1]),"",[1] & IIf(IsNull([2] And IsNull([3],".",", ")) & IIf(IsNull([2]),"",[2] & IIf(IsNull([3],".",", ")) & IIf(IsNull([3]),"",[3] & ".")
    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
    bburton is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2011
    Posts
    15
    That would work, however there is going to be over 20 different fields listed in there which would make that a bit too long and complicated while using that method. I am hoping to find another method that would simply just look at the end of the box and replace the last comma with a period.

  4. #4
    Rhino373 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    May 2011
    Posts
    65
    How about something using the Left(), Len() and Concatenate functions?

    Left(IIf(IsNull([1]),"",[1] & ", ") & IIf(IsNull([2]),"",[2] & ", ") & IIf(IsNull([3]),"",[3] & ", "),Len(IIf(IsNull([1]),"",[1] & ", ") & IIf(IsNull([2]),"",[2] & ", ") & IIf(IsNull([3]),"",[3] & ", "))-2) & "."

  5. #5
    bburton is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2011
    Posts
    15
    If the fields were blank, then it'd still leave those punctuations wouldn't they? So that wouldn't work out as well as I'd like it to.

  6. #6
    Rhino373 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    May 2011
    Posts
    65
    No, if the fields were blank they wouldn't leave a comma or a space. According to your example it only enters a comma and space if the field was not blank.

    All my example does it take exactly what you have and find everything but the last two characters (which would be a comma and a space) and replace them with a period.

  7. #7
    bburton is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2011
    Posts
    15
    Quote Originally Posted by Rhino373 View Post
    No, if the fields were blank they wouldn't leave a comma or a space. According to your example it only enters a comma and space if the field was not blank.

    All my example does it take exactly what you have and find everything but the last two characters (which would be a comma and a space) and replace them with a period.
    Hmm, well I just tried it out (Field 1 blank, 2 inputted, 3 blank) and it basically spat out " , 1 7/8" Pintle, . " Both commas should not be there, only the period should be there.

  8. #8
    Rhino373 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    May 2011
    Posts
    65
    It would appear the fields you are testing for aren't blank. Based on your output they appear to be filled with spaces. You need to use a Trim() function against them to clear the spaces

  9. #9
    Rhino373 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    May 2011
    Posts
    65
    Rather the fields you are testing for aren't NULL

  10. #10
    bburton is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2011
    Posts
    15
    Ah I see where those spaces were coming from. My IIf statements were making them spaces rather than null when I was doing:

    IIf(IsNull([1]),"",[1])

    I replaced the "" with Null and it seemed to work now. Just that when they are all blank, it has a period. Just one period isn't a big issue really. If this was fixable, great. Thanks for the help.

  11. #11
    Rhino373 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    May 2011
    Posts
    65
    You could surround the entire statement with another IIF that basically says if the LEN(statement) = 1 then NULL else (statement). This effectively replaces the single period with NULL. In no other instance would the length be 1 if at least one field had data. The minimum length would then be at least 2.

    No problem!

  12. #12
    bburton is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2011
    Posts
    15
    Hmm, I must be doing it wrong because I keep getting number of arguments is incorrect... Last pitch here if you don't mind please? Thanks!

    =IIf(Len(IIf(IsNull([1]),"",[1] & ", ") & IIf(IsNull([2]),"",[2] & ", ") & IIf(IsNull([3]),"",[3] & ", ") & IIf(IsNull([4]),"",[4] & ", ") & IIf(IsNull([5]),"",[5] & ", "))-2) & ".")=1,Null,Left(IIf(IsNull([1]),"",[1] & ", ") & IIf(IsNull([2]),"",[2] & ", ") & IIf(IsNull([3]),"",[3] & ", ") & IIf(IsNull([4]),"",[4] & ", ") & IIf(IsNull([5]),"",[5] & ", "),Len(IIf(IsNull([1]),"",[1] & ", ") & IIf(IsNull([2]),"",[2] & ", ") & IIf(IsNull([3]),"",[3] & ", ") & IIf(IsNull([4]),"",[4] & ", ") & IIf(IsNull([5]),"",[5] & ", "))-2) & "."

    EDIT: I got it now...

  13. #13
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Did you say there would be over 20 fields involved? Possible expression in ControlSource will hit a string length limit whichever way you go.

    Options:
    Calculate the string in a hidden box then in a visible box fix the last comma using Rhino's idea referencing the hidden control.
    Still too long? Break up into 20 boxes (hidden), each with expression to determine one term and another textbox that concatenates the other 20 and fixes the comma.
    Write a function that will return the desired string. Would probably involve a recordset in VBA.
    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.

  14. #14
    bburton is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2011
    Posts
    15
    Yep, about 24 options. Currently I have it set up where on another report, it takes the inputted fields from the form then converts them into the correct string/term that they need to be. They will then transfer over to the exporting report where it'll all be combined into the correct format with commas separating them and a period to end it.

    All the fields should be named 1-24 to reduce the amount of space it will take. Hopefully it will not hit the cap.

    I will also be making the calculating string hidden then output it into another box whilst fixing that last punctuation. If this all works out, it should work perfectly. I hope... Thank you all for your help.

  15. #15
    Rhino373 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    May 2011
    Posts
    65
    tell me what this does:

    IIf(Len(IIf(IsNull([1]),"",[1] & ", ") & IIf(IsNull([2]),"",[2] & ", ") & IIf(IsNull([3]),"",[3] & ", ") & IIf(IsNull([4]),"",[4] & ", ") & IIf(IsNull([5]),"",[5] & ", ") & ".")=1,Null,Left((IIf(IsNull([1]),"",[1] & ", ") & IIf(IsNull([2]),"",[2] & ", ") & IIf(IsNull([3]),"",[3] & ", ") & IIf(IsNull([4]),"",[4] & ", ") & IIf(IsNull([5]),"",[5] & ", ") & "."),Len(IIf(IsNull([1]),"",[1] & ", ") & IIf(IsNull([2]),"",[2] & ", ") & IIf(IsNull([3]),"",[3] & ", ") & IIf(IsNull([4]),"",[4] & ", ") & IIf(IsNull([5]),"",[5] & ", ") & ".")-3) & ".")

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

Similar Threads

  1. Allow a period in a table field name
    By escapades_access in forum Database Design
    Replies: 9
    Last Post: 07-08-2011, 09:21 AM
  2. Set Database to Expire in time period
    By robsworld78 in forum Access
    Replies: 12
    Last Post: 06-07-2011, 06:54 AM
  3. Replies: 5
    Last Post: 02-20-2011, 08:22 PM
  4. Help in Solving Warranty Period in Access
    By vdanelia in forum Access
    Replies: 4
    Last Post: 01-29-2011, 04:28 PM
  5. Replace a string/text in ms-access db
    By anziga in forum Queries
    Replies: 4
    Last Post: 12-31-2010, 06:40 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