By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,889 Members | 1,297 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,889 IT Pros & Developers. It's quick & easy.

Changing the input mask with code

P: 1
Access beginner,
Hi,
Im using code to unlock information so the user can change the information. I also need the input mask to change from "password" to "text", but im struggling with that specific part of the code.
Thanks
Theuns

Private Sub EmployeeCode_Enter()
Dim strInput As String, strMsg As String

strMsg = "'Action code'is password protected."
strInput = InputBox(prompt:=strMsg, _
Title:="Emplyee 'action code'")
If strInput = "CLR" Then
Me.EmployeeCode.Locked = False
'Me.EmployeeCode.InputMask = text
'InputMask = password
Else
Me.EmployeeCode.Locked = True

End If
Aug 16 '07 #1
Share this Question
Share on Google+
5 Replies


missinglinq
Expert 2.5K+
P: 3,532
The question that has to be asked is "Why?" If you feel it's important enough to require an input mask in one instance, why would you change that in another instance? At any rate, the simple fact is that you can't! Input masks can only be defined in Design View.

Also, when using most Input Masks (it doesn't really matter for Password) be sure in use code like this to assure that if the user clicks on the textbox the cursor will go to the beginning of the field. Otherwise the insert point will be wherever they clicked in, and they'll waste time redoing it!

Expand|Select|Wrap|Line Numbers
  1. Private Sub YourTextBoxName_Click()
  2.    Me.YourTextBoxName.SelStart = 0
  3. End Sub
  4.  
If your Access default for Entering a Field is set to anything other than "Go to start of field," also use this

Expand|Select|Wrap|Line Numbers
  1.  Private Sub YourTextBoxName_GotFocus()
  2.   Me.YourTextBoxName.SelStart = 0
  3. End Sub
Welcome to TheScripts!

Linq ;0)>
Aug 16 '07 #2

ADezii
Expert 5K+
P: 8,669
Access beginner,
Hi,
Im using code to unlock information so the user can change the information. I also need the input mask to change from "password" to "text", but im struggling with that specific part of the code.
Thanks
Theuns

Private Sub EmployeeCode_Enter()
Dim strInput As String, strMsg As String

strMsg = "'Action code'is password protected."
strInput = InputBox(prompt:=strMsg, _
Title:="Emplyee 'action code'")
If strInput = "CLR" Then
Me.EmployeeCode.Locked = False
'Me.EmployeeCode.InputMask = text
'InputMask = password
Else
Me.EmployeeCode.Locked = True

End If
You can programmatically change the Input Mask for a Control, but as indicated by missingling, why? If you insist, the logic wouold be something similar to:
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtTest_GotFocus()
  2.   If <some condition> = True Then
  3.     Me![txtTest].InputMask = "Password"
  4.   Else
  5.     Me![txtTest].InputMask = "000-00-0000"
  6.   End If
  7. End Sub
Aug 16 '07 #3

missinglinq
Expert 2.5K+
P: 3,532
Didn't realize that, ADezii! Access Help doesn't mention this; what a surprise!

Linq ;0)>
Aug 16 '07 #4

ADezii
Expert 5K+
P: 8,669
Didn't realize that, ADezii! Access Help doesn't mention this; what a surprise!

Linq ;0)>
Like you stated earlier, it's something you wouldn't normally do with code, but there's always a first.
Aug 16 '07 #5

P: 1
I know this is an ancient thread, but it points out something that novices and experts alike need to remember: don't ask WHY, just answer the question.

In this case, it is now more and more common to see a "show" checkbox (cell phones and desktops both) so you can see your password when no one is looking over your shoulder.

Here, the "beginner" is showing the "experts" something they could have used!

Tom the Toolman
Sep 30 '18 #6

Post your reply

Sign in to post your reply or Sign up for a free account.