Results 1 to 2 of 2
  1. #1
    gmazziri is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jun 2016
    Posts
    5

    Update/change field value table A using infor from table B VBA

    Hello, I'm still learning VBA so any help will be appreciated
    I'm trying to create a form to change the password on my UsingLoginT
    this is the login form code:
    --------
    Private Sub loginYes_Click()
    Dim UserLevel As Integer
    If IsNull(Me.username1) Then
    MsgBox "Por favor, escriba su Usuario", vbInformation, "Usuario requerido"
    Me.username1.SetFocus
    ElseIf IsNull(Me.password1) Then
    MsgBox "Por favor, ingrese su Contraseņa", vbInformation, "Contraseņa requerida"
    Me.password1.SetFocus
    Else
    If (IsNull(DLookup("[loginusername]", "UserLoginT", "[loginusername] ='" & Me.username1.Value & _
    "' And loginpassword = '" & Me.password1.Value & "'"))) Then
    MsgBox "Usuario y/o Contraseņa incorrectos"
    Else
    'saving login information
    Dim dbsSafety As DAO.Database
    Dim rstRecord As DAO.Recordset
    Set dbsSafety = CurrentDb
    Set rstRecord = dbsSafety.OpenRecordset("userloginrecordt")
    Dim varX As String
    Dim varY As String
    varX = DLookup("idlogin", "UserLoginT", "Loginusername = '" & Me.username1.Value & "'")
    rstRecord.AddNew
    rstRecord!recordlogindate = Date
    rstRecord!recordloginuser = varX
    rstRecord!recordloginuserwindows = Environ$("Username")
    rstRecord.Update
    'Defining what kind of access will have
    UserLevel = DLookup("LoginUserType", "UserLoginT", "loginusername = '" & Me.username1.Value & "'")
    If Check12 = False Then


    If UserLevel = 1 Then
    DoCmd.Close
    MsgBox "Bienvenido!!!", , "Administrador"
    Else
    DoCmd.Close
    DoCmd.OpenForm "InicioF"
    End If
    Else
    DoCmd.Close
    DoCmd.OpenForm "loginchangepasswordf"
    End If
    End If
    End If
    End Sub
    -----------------

    And this is the form with the one i want to change the password
    ---
    Private Sub Command4_Click()
    If Me.Text0 = Me.Text2 And Len(Me.Text0) & "" > 0 Then
    'update [loginpassword] in "UserloginT" using last record of "userloginrecordT" in field [loginid] ?????
    DoCmd.Close
    DoCmd.OpenForm "inicioF"
    Else
    MsgBox "New Password entries do not match. Re-enter ." _
    & vbCrLf & "and please try again.", vbCritical, _
    "Re-enter both Passwords."
    End If
    End Sub

    thanks in advance.

  2. #2
    gmazziri is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jun 2016
    Posts
    5
    I have this so far and it's working. still testing. open to any suggestion.
    Private Sub Command4_Click()
    If Me.Text0 = Me.Text2 And Len(Me.Text0) & "" > 0 Then
    'update [loginpassword] in "UserloginT" using last record of "userloginrecordT" in field [loginid]
    Dim dblogin1 As Object
    Dim rstuserlogint As Object
    Dim fldEnumerator As Object
    Dim fldColumns As Object
    Set dblogin1 = CurrentDb
    Set rstuserlogint = dblogin1.OpenRecordset("userlogint")
    Set fldColumns = rstuserlogint.Fields
    Dim currentuser1 As String
    currentuser1 = DLast("recordloginuser", "userloginrecordt")
    ' Scan the records from beginning to each
    While Not rstuserlogint.EOF
    ' Check the current column
    For Each fldEnumerator In rstuserlogint.Fields
    ' If the column is named Title
    If fldEnumerator.Name = "IdLogin" Then
    ' If the title of the current record is "Congo"
    If fldEnumerator.Value = currentuser1 Then
    ' then change its value
    rstuserlogint.Edit
    rstuserlogint("loginpassword").Value = Me.Text0.Value
    rstuserlogint.Update
    End If
    End If
    Next
    ' Move to the next record and continue the same approach
    rstuserlogint.MoveNext
    Wend
    DoCmd.Close
    DoCmd.OpenForm "inicioF"
    Else
    MsgBox "New Password entries do not match. Re-enter ." _
    & vbCrLf & "and please try again.", vbCritical, _
    "Re-enter both Passwords."
    End If
    End Sub

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

Similar Threads

  1. Replies: 3
    Last Post: 02-17-2014, 12:56 AM
  2. Replies: 7
    Last Post: 03-21-2013, 09:43 AM
  3. Replies: 5
    Last Post: 11-01-2012, 09:26 AM
  4. Replies: 3
    Last Post: 01-17-2011, 01:48 AM
  5. Replies: 4
    Last Post: 09-03-2009, 02:01 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