Modifying Existing VBA code programatically

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a means up updating VBA code programatically (i.e.: using a sub
linked to a control's click event, to modify an existing function)?

I'm trying to create a change password form that modifies an If..Then
statement in my password verification function. For example, in the below
line I want to be able to write a sub that will change the string "123" into
whatever I enter into my form.

If mstrMaintPW = "123" Then

Thanks is advance! :)
 
You would be better off to store the password in a table.
If you are concerned about someone seeing the code in the table, it doesn't
really matter, the same person could find it in the code; however, here is an
encryption routine that will make the password unreadable:

Public Function EncryptCode(iToDo As Integer, strPass As String, _
Optional iSeed As Integer) As String
Dim strValue As String
Dim lngMxx As Long
Dim lngPlace As Long

iSeed = IIf(iSeed = 0, 105, iSeed + 95)

For lngMxx = 1 To Len(strPass)
If iToDo = 1 Then
' encode
lngPlace = (Asc(Mid(strPass, lngMxx, 1)) + 2550 + iSeed - lngMxx)
Mod 255
Else
' decode
lngPlace = 255 - (Abs((Asc(Mid(strPass, lngMxx, 1)) - 2550 -
iSeed + lngMxx) Mod 255))
End If
strValue = strValue + Chr(lngPlace)
Next

EncryptCode = strValue

End Function
 
Back
Top