I have a textbox that holds credit card numbers. I want to be able to print these numbers in a report but to display X's instead of the numbers. Example if the number is like this : 5262 1234 5678 9012 it would print instead like this
XXXX XXXX XXXX 9012.
Please help
Hi. There are many ways to do this. The simplest I can think of works if the card number is stored as a text string, and it is to extract the last four characters of the card number using the string function
Right.
You can use the following directly in the controlsource property of the textbox in your report, changing the name of the textbox to something different to prevent a circular reference to the name of the creditcard number field:
- ="XXXX XXXX XXXX " & Right$([name of your cardnumber field], 4)
If you use this form of display frequently it is a simple matter to make this a custom function which you can call whenever required:
- Public Function PartialCardnumber(cardnumber as string) as string
-
PartialCardnumber = "XXXX XXXX XXXX " & Right$(cardnumber, 4)
-
End Function
This function would be pasted in to any public code module (those you see when you select the Module tab of your database, or a new module if you don't have any existing public modules). It can be used in your report textbox by placing the following statement in the controlsource property:
- =PartialCardNumber([name of your cardnumber field])
-Stewart
**Edit** Apologies to Linq who replied more or less simultaneously to the same question. Both answers are on similar lines...