Replace & Len to create asterisk...

MackMan

Registered User.
Local time
Today, 16:30
Joined
Nov 25, 2014
Messages
174
Hi all.

In order to hide some sensitive data, specifically around account numbers etc, I'm trying to replace the first half of the text within a textbox with asterisks.

example; turning AG7465LFR721 into ******LFR721


In this instance Account numbers are various lengths (including text) and need to replace half of the strings with *'s to users who do not need to know this.

Len Counts the number of characters.
If it's even I divide by two. If it's odd, I divide by 2, then add 1.

This gives me the number of characters to replace, but despite looking here and google (all search results show how to search using *'s and hide all text with * (like password entry) I'm failing on vba's replace function.

Is this even possible at data entry point, or will I need to create an unbound text box, then pass with values to the bound text box using after update?

I understand the syntax of the replace function
Code:
Replace ( string1, find, replacement, [start, [count, [compare]]] )
but fail to see how I could implement this without lengthy code to count each character in turn (find), then replace it with an asterisk (replace)...

Or if it's possible, I'm totally going about it the wrong way... and there is a really simple solution I'm not looking at?

any help to point me in the right direction would be greatly appreciated.
I'm not looking for code how it can be done, but a "gentle" nudge in the right direction so I can learn, if there's an easier solution.
 
Replace probably isn't the way to go. I would start off by making a string of asterisks as long as the longest account:

Dim asterisks As String ="************"

Then determine the length of string you want to replace from the actual string.

Then its simple concatenation. You would use Mid (http://www.techonthenet.com/access/functions/string/mid.php) to get the number of asterisks to use and to that you add the remaining portion of the actual string--again using Mid.

Hopefully that's push enough, if not, post back what you have.
 
Hi Plog. Thanks. I'll go have a look, and let you know.
 
it's easy when you know how. ;)
I've never had much use for MID up to now, but I think it'll come in rather handy going forward.

As always , much appreciated.
 

Users who are viewing this thread

Back
Top Bottom