Update a table using VB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BabyLucifer666
    New Member
    • Jun 2010
    • 13

    Update a table using VB

    Hello Again, (although I haven't figured out my other problem yet, I decided to tackle another obstacle!)

    what I am trying to accomplish:
    The Trainer will click a checkmark when a trainee finishes a specific class, this opens a prompt for the Trainer's password. When the password is entered, you push a button, the prompt closes and updates a field in the main form with the Trainer's name and another textbox with the current date.

    What I've got...
    I have a form named "frmRequiredGen eral" that lists the classes that a specific trainee needs to take in a continuous form. On this form are the Classname (txtClassName) a checkbox, (chkClassTaken) , two textboxes (txtTrainer and txtDateTaken) all bound to tblRequiredClas ses.

    The checkbox, when true, opens frmPasswordReq, which is bound to a qry that displays all current employees and their passwords. I have an unbound textbox (txtTrainerpass word) and a command button (btnUpdate)

    Hope this make sense so far.

    What I want is the button once clicked, to update the Trainer field in frmRequiredGene ral with the trainers name after he inputs his password into the frmpasswordreq.

    I have some idea how to go about this, but nothing I've done has worked at all.

    Any help is much appreciated! (I am a 'tard with VB so please be gentle!!)
    *_*BL
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32633

    #2
    Surely first the trainer would select their name from [txtTrainer]. This should be disallowed in the code if [chkClassTaken] is already True. Continuous form's controls cannot be set locked/unlocked per record. They are form-wide.

    When a name has been entered a prompt should pop-up (with format of "password" so not visible) to request the password. This would never be shown anywhere on the form. If the password matches then [chkClassTaken] should be set to True and the record saved.

    Does this make sense to you?

    Comment

    • BabyLucifer666
      New Member
      • Jun 2010
      • 13

      #3
      I changed the txtTrainer text box to a combo box and renamed it cboTrainer. Then added an afterupdate for cboTrainer to open the form frmPasswordReq. (The combobox source is the qryCurrentEmplo yees, with fields labeled "LogOnName" and another for "Password")

      How do I link cboTrainer from sfrmRequiredGen eral to txtTrainerPassw ord in sfrmTrainerPass word?

      The password doesn't need to be saved anywhere just used as a confirmation of identity. It comes from a linked table called tblSecurity from another database.

      In regards to being unable to lock 'Trainer' after entering the password; Is there anything you can suggest in replacement of this? I wish to block users from changing the Trainers' name or date once the information has been put it. I'm using a continuous form because it was the best way for me to show all the required classes that a Trainee had to take, rather than having to update one at a time, the Trainer can update multiple.

      Thanks Again,
      BL

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32633

        #4
        Originally posted by BabyLucifer666
        BabyLucifer666: I changed the txtTrainer text box to a combo box and renamed it cboTrainer. Then added an afterupdate for cboTrainer to open the form frmPasswordReq. (The combobox source is the qryCurrentEmplo yees, with fields labeled "LogOnName" and another for "Password")
        I see no requirement for reading in the passwords - even in encrypted form.
        Originally posted by BabyLucifer666
        BabyLucifer666: How do I link cboTrainer from sfrmRequiredGen eral to txtTrainerPassw ord in sfrmTrainerPass word?
        You don't.
        Originally posted by BabyLucifer666
        BabyLucifer666: The password doesn't need to be saved anywhere just used as a confirmation of identity. It comes from a linked table called tblSecurity from another database.
        Indeed. Assuming you're using encryption then compare the encrypted version of the password entered into your unbound password TextBox with the associated value in the table from the record which matches the user name supplied and Bob's your uncle.
        Originally posted by BabyLucifer666
        BabyLucifer666: In regards to being unable to lock 'Trainer' after entering the password; Is there anything you can suggest in replacement of this? I wish to block users from changing the Trainers' name or date once the information has been put it. I'm using a continuous form because it was the best way for me to show all the required classes that a Trainee had to take, rather than having to update one at a time, the Trainer can update multiple.
        I would suggest a BeforeUpdate() of [cboTrainer] and set Cancel = True if you find [chkClassTaken] to be true. In other words :
        Code:
        Private Sub cboTrainer_BeforeUpdate(Cancel As Boolean)
          Cancel = Me.chkClassTaken
          'You may want to include operator notification...
          If Cancel Then
            'MsgBox(etc)
          End If
        End Sub

        Comment

        • BabyLucifer666
          New Member
          • Jun 2010
          • 13

          #5
          Hello Again,

          I'm still attempting to accomplish this the way I had originally imagined it. So far I have accomplished a few things:

          I have the main form with a subform, "sfrmrequiredge neral", it has a yes/no control, "chkClassTaken" , and three text fields "txtTrainer " and "txtTrainee " and "DateTaken"

          when chkClassTaken = -1(true) "frmTrainerPass wordReq" opens, it has one unbound text field with the following code as its afterupdate:

          Code:
          Private Sub txtTrainerpassword_AfterUpdate()
              Dim WhoIsIt As String
              
              WhoIsIt = Nz(DLookup("[LogOnName]", "qryPasswordLookup", "[Password] = txtTrainerpassword"))
              If WhoIsIt = "" Then
                  MsgBox "Invalid Password."
                  Me.txtTrainerpassword = ""
                  GoTo Ending
              End If
              Me.txtTrainerpassword.Value = WhoIsIt
              Me.txtTrainerpassword.InputMask = ""
          
          Ending:
          End Sub
          When I type in my password (***) it returns my Name. I want that value to be entered into the textfield in the subform for trainer using a button (maybe), an update query?? i dunno, but thats what i want, is it possible?

          Thank you much...
          BL

          Comment

          • BabyLucifer666
            New Member
            • Jun 2010
            • 13

            #6
            I figured this out. I have a button, btnUpdate, when clicked :

            Code:
            Private Sub btnUpdate_Click()
                Form_sfrmRequiredLevelI.txtTrainee.Value = Me.txtTraineepassword
                DoCmd.Close
                
            End Sub
            So basically, the check leads to the password form, the form looks ups the user based on the password entered (code in previous reply) and the button updates the subform with the text from the password form. the textbox on the subform is kept locked so it can not be edited by anyone else. yay.
            BL

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32633

              #7
              Have you considered what would happen if two users chose the same password?

              I did try to warn you against this approach BL, but ultimately only you decide which approach you use.

              Comment

              • BabyLucifer666
                New Member
                • Jun 2010
                • 13

                #8
                We discussed it recently in a meeting, we work with people that have very little computer knowledge, the system admin, myself and the Training manager decided to create a password based on the employees initials and birthdate. I personally don't agree with it, but its not my call.

                Thanks for your help however.

                BL

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32633

                  #9
                  'Tis often the way I fear. Those with understanding are so rarely in positions to make the decisions.

                  Good luck anyway :)

                  Comment

                  Working...