Results 1 to 15 of 15
  1. #1
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185

    Question Using VBA to change VBA

    Is it possibe to use code in one form to change code in another? Example:



    I have this code on a PW entry form....

    Code:
    Private Sub DEOK_Click()
    Dim stDocName As String
        Dim stLinkCriteria As String
     
        stDocName = "DETechOptions"
        If [DEPW] = "Data111" Then
        DoCmd.Close
        DoCmd.OpenForm "DETechOptions"
        DoCmd.GoToRecord , , acNewRec
     
        Else
        MsgBox ("Seriously? Try again.")
     
    Exit_DEOK_Click:
        Exit Sub
    Err_DEOK_Click:
        MsgBox Err.Description
        Resume Exit_DEOK_Click
     
    On Error GoTo Err_DEOK_Click
     
        End If
    End Sub
    I want to create a change PW button on this form that takes you to another form where if the enduser puts in the current correct PW it will allow them to change the code, in this instance from "Data111" to whatever they want, and obviously I would want them to have to enter the new PW twice to verify its correct.

    Could someone please give an example of how this is achievable?

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    IMO it would be a mistake to store the password in code. Typically you'd have a users table with fields for user ID, password, etc. You'd look up the password there, and change it there if the user decided to change their password. A user password is a piece of data, and should be treated as such. If this is a global password (not user specific), I'd still keep it in a table.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185
    Thanks, that is how I am eventually going to do it but Im trying to learn more about VBA. I am trying to understand the steps in my previous question. Can someone explain to me or better yet show me an example of the steps in the code I'm trying to perform? I have somewhat of an idea but I cant seem to get it right. Thanks in advance.

  4. #4
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185
    Actually I'm a little stuck with what you mentioned as well. So far I have a table with the fields, "UserName" and "Password" no PK, and a form with two textboxes, UserName and Password.

    There are three buttons OK which Will need an on click event for allowing access to the next form, a cancel button which will just have a do.cmd.close on click and then the third button is the "ChangePasswordButton". First of all is this the right way to go about it? And if so, on the OK button what is the code for the click event to make sure the UN and PW together have to equal a record in order to allow access to next page and what would the code look like on the change PW button to change the code. I would like the change PW form to to have a textbox to input UN and Current PW then two textboxes to change the UN's PW and of course both "new PW" textboxes would have to be exactly the same in order to change.

    Am I nukeing this out? Is there an easier way? If so could you please explain with examples of code? Thanks. Also still want to know the first question also if you please.

  5. #5
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I've never used them, but you can see if InsertLines and DeleteLines do what you want. I would not go that way.

    Your proposed method is fine. The change password button can execute an update query to change the password in the table. You could also open a recordset on the table to get/compare the existing password, and use the Edit method of the recordset to change it. That would require the recordset stay open for more than one event, so the SQL method might be simpler for you.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Desstro,

    Paul has obviously covered what is right, but I'd like to add something about using the extensibility library. IMO, there's never really a need to use it. One useful purpose is this though: http://www.ajenterprisesonline.com/_...me=DelComments

    That of course is just useful if you're not deploying an executable. I use the extensively lib myself quite a bit, because a lot of the mysql database information I have stored cannot be parsed through phpMyAdmin because it's too complex and I have to use vba's extensive abilities to print the actual codes and functions out to tables so certain special characters can be escapedwhen run with PHP. It's actually quite unique.

    The ext. library is very powerful, but as stated already, there's no need to use it. Again IMO, if you want to learn about the power of VBA, learn more about class modules and API function that can be called by the language. The thing I've always found interesting about Visual Basic (since I learned it) is the fact that it is nothing more than a "more readable" version of what windows already does whenever you move a mouse or click something.

    For example, form controls have much more to them other than what is listed with the intellisense (methods and properties). If you seriously want to study it, pipe out the data dumps from the windows SDK, or other tool and start deciphering the machine language that is used to create DLLs. There's approximately 70,000 API functions within the system folder in windows alone, so that gives you some idea of how endless the possibilities are when you use the API.

    That'll make you a smart cookie!

  7. #7
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185
    sorry I haven't attended to this thread in a while, I have been on the road a bit.

    Thanks all for the replies, however, I have been stuck trying all sorts of ways to accomplish this task. I am a bit frustrated because it seems as if it should be a simple bit of work but everything I try does not work. So I am going to ask for a cheat and ask if someone would write the code(s) for me partly so I can see what I am doing wrong but mostly because I am in a bit of a time crunch for this DB.

    Table: "UNandPW" has two fields...UserName and PassWord
    Form: "Switchboard" lets say has just one button..."Scheduler"When the scheduler button is pushed, I would like a form which will be called "EnterPassword"frm to open. Easy enough, I can do that.

    On the "EnterPassword"frm there will be one textbox for entering the schedulers password in. There will be three buttons...
    "OK"--will allow access to a form called "SchedulersOptions" if the password is correct, else messagebox, "Sorry, the password you have entered is incorrect"

    "Cancel"---which will simply close the "EnterPassword"frm

    "ChangePassword"--which will open a new form that will be called "ChangePW"frm.

    On this form, I will need three textboxes, the first...
    "CurrentPassword" enabled set to yes
    "New Password" enabled set to no
    ConfirmNewPassword" enabled set to no

    If the Current password typed in is correct, enable the other two textboxes

    after the user enters the desired new password into both New and Confirm, I would like there to be a button, lets call it, "Submit"

    When Submit is pushed, if the New and confirm are not identicle, then msgbox, "Sorry, your new password does not match the confirm password. Please try again.

    If it does match I would like the password in the table, "UNandPW" to be changed to the new desired password.

    There will also be a cancel button on the ChangePWfrm which simply closes the form.

    Where I would like the codes for are the "OK" button on "EnterPassword"frm and pretty much everything for the "ChangePW"frm. Could someone please write these codes for me so I can stop banging my head on the keyboard?

    By the way, I am not above paying for learning, often there is an area in forums to donate, but I have not found one here, is there one?

  8. #8
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185
    Got the OK button figured out.

    Code:
    Private Sub OK_Click()
     
    Dim stDocName As String
    Dim stLinkCriteria As String
     
    stDocName = "Form to open if PW is correct"
     
    If Me.TextBoxName.Value = DLookup("Field", "Table") Then
    DoCmd.Close
    DoCmd.OpenForm "Form to open if PW is correct"
    DoCmd.GoToRecord , , acNewRec
     
    Else
     
    MsgBox ("Sorry, the password you entered is incorrect. Please try again.If this error persists, please contact your database administrator.")
     
    Exit_OK_Click:
    Exit Sub
     
    Err_OK_Click:
    MsgBox Err.Description
     
    Resume Exit_OK_Click
    On Error GoTo Err_OK_Click
     
    End If
     
    End Sub

  9. #9
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185
    Super Close...I think. This is what I have so far for the Change password form....

    Code:
    Private Sub ConfirmNewPassword_AfterUpdate()
     
    'moves the focus so I can clear the text boxes later
    DoCmd.GoToControl "CurrentPassword"
    If Me!ConfirmNewPassword = Me!NewPassword Then
    'update to the new password and tell user
    HELP PLEASE I cant figure out what to put here to get the "PW" field
    to change in the table to what the "NewPassword" is being desired on this form. HELP PLEASE
    MsgBox "Password has been changed"
    Else
    MsgBox "Failed. Passwords have NOT been changed"
    End If
    'clear the text boxes and disable
    Me!NewPassword = ""
    Me!ConfirmNewPassword = ""
    Me!CurrentPassword = ""
    Me!NewPassword.Enabled = False
    Me!ConfirmNewPassword.Enabled = False
    End Sub
    This is what I have on the after update for the CurrentPassword textbox...

    Code:
    Private Sub CurrentPassword_AfterUpdate()
     
    'if the user knows the existing password, allow him to change it
    If Me.CurrentPassword.Value = DLookup("PW", "Utility") Then
    Me!NewPassword.Enabled = True
    Me!ConfirmNewPassword.Enabled = True
     
    Else
     
    Me!NewPassword.Enabled = False
    Me!ConfirmNewPassword.Enabled = False
    MsgBox "Password is incorrect"
     
    End If
     
    End Sub
    Also Just for note, I have created a practice DB to try to figure this out. Table and form names are different from the original post.

    Table is now: Utility---Done
    Form1: EnterPW---Done
    Form2: Acuren---Simply the form I am trying to get access to after a password is entered---Done
    Form3: ChangePW---still working on code to allow form to change the data in the table.---NOT Done

  10. #10
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    One method:
    Code:
      CurrentDb.Execute "UPDATE tblUsers SET tblUsers.UserPassword = '" & Me.txtCnfPW & "' " & _
                        "WHERE (((tblUsers.UserName)='" & Me.txtUserID & "'));"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185
    You are the man!!! Thank you. I thank both of you for your continued support!

    Consider this thread solved!!!

  12. #12
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185
    oops...one last thing, everything is working fine except how do I make the new and confirm new passwords case sensative?

    As it is now I could type in ABCD1234 as new PW ans abcd1234 as confirmed and it accepts it. Needs to be case sensative.''

    Any suggestions? Is it something in the table or code?

  14. #14
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    There are probably other ways, but you can play with the options available in the

    Option Compare...

    statement at the top of the module.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  15. #15
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185
    OK. Thanks again!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Field Name Change
    By MelindaP in forum Forms
    Replies: 8
    Last Post: 07-01-2010, 12:03 PM
  2. Using VB to change the value in a combo box
    By Noobie in forum Programming
    Replies: 7
    Last Post: 03-18-2010, 10:07 AM
  3. Change DOB to age
    By denl10 in forum Access
    Replies: 2
    Last Post: 02-04-2010, 02:18 AM
  4. Change the value of a field
    By akhilash in forum Queries
    Replies: 0
    Last Post: 07-16-2009, 07:20 AM
  5. Name Change
    By skip17 in forum Access
    Replies: 0
    Last Post: 01-12-2009, 01:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums