I've got a text box named ActivationCodeBox on a form where the user will enter a string of characters (numbers or letter) and then click the Enter button. Currently the text box is Unbound. I want the string of characters entered by the user to be compared to a variable called EntryCode. If they are equal then I want the form to close but if they aren't equal then I want a message to display. This is what I have:
Private Sub EnterActivationCodeCMD_Click()
Dim x As Integer
Dim EntryCode as String
EntryCode = ActivationCodeBox.Text
'The EntryCode that will be entered in the text box is
'actually the computer name where each letter/number has
'been incremented by one
For x = 1 To Len(EntryCode)
Mid(EntryCode, x, 1) = Chr(Asc(Mid(EntryCode, x, 1)) +1)
If Mid(EntryCode, x, 1) = "[" Then
Mid(EntryCode, x, 1) = "A"
ElseIf Mid(EntryCode, x, 1) = ":" Then
Mid(EntryCode, x, 1) = "1"
End If
Next
If EntryCode = Environ("ComputerName") Then
DoCmd.Close
ElseIf EntryCode <> Environ("ComputerName") Then
MsgBox "You did not enter a valid Activation
Code."
End If
End Sub
The problem I am having is when I enter something in the text box and click on the Enter button, I am getting a run time error '2185' that says "You can't reference a property or method for a control unless the control has the focus." When I click Debug, the line of code that is highlighted is "EntryCode = ActivationCodeBox.Text"
Can someone please help me.
Thanks,
ML
Private Sub EnterActivationCodeCMD_Click()
Dim x As Integer
Dim EntryCode as String
EntryCode = ActivationCodeBox.Text
'The EntryCode that will be entered in the text box is
'actually the computer name where each letter/number has
'been incremented by one
For x = 1 To Len(EntryCode)
Mid(EntryCode, x, 1) = Chr(Asc(Mid(EntryCode, x, 1)) +1)
If Mid(EntryCode, x, 1) = "[" Then
Mid(EntryCode, x, 1) = "A"
ElseIf Mid(EntryCode, x, 1) = ":" Then
Mid(EntryCode, x, 1) = "1"
End If
Next
If EntryCode = Environ("ComputerName") Then
DoCmd.Close
ElseIf EntryCode <> Environ("ComputerName") Then
MsgBox "You did not enter a valid Activation
Code."
End If
End Sub
The problem I am having is when I enter something in the text box and click on the Enter button, I am getting a run time error '2185' that says "You can't reference a property or method for a control unless the control has the focus." When I click Debug, the line of code that is highlighted is "EntryCode = ActivationCodeBox.Text"
Can someone please help me.
Thanks,
ML