Consulting

Results 1 to 4 of 4

Thread: How to update personal details on MS ACCESS as a user?

  1. #1

    How to update personal details on MS ACCESS as a user?

    Hi,

    I am working on Microsoft Access 2016.

    I have created a registration form which enables me to become a member once registered and my data gets stored in the tblMember table.

    I have created a login system for members where they can update their personal details once logged in. I connected the update membership form to the homepage.

    When creating the update form, I added existing fields from the membership table which means the details are already saved on the fields when a member clicks on the membership details page.
    However the issue is, it stores the information of the latest member on the update form. For example, I registered a member with a name of John, and his details will also be updated on update form because of the fields being added directly from the tblMember table. However if I log in as Peter (account I created previously), it still shows the details of John on the update form. The updated form will only show the details on the latest member regardless of who I login as.

    I am assuming I will need to do some sort of query to make sure whoever logs in, can update their own personal details instead of the form showing details of the latest member. Does anyone know how I can make this work? I have been trying to figure this out for quite some time and had no luck. Many thanks

    Here is my coding:

    Register member:

    PrivateSub btnSubmit_Click()
    
    OnErrorGoTo ErrHandler:
    If IsNull(MemberID)Then
       MsgBox "Please enter your personal details",,"Data Required"
    ElseIf IsNull(Title)Then
        MsgBox "Title is required",,"Required Field"
    ElseIf IsNull(FirstName)Then
        MsgBox "First Name is required",,"Required Field"
    ElseIf IsNull(LastName)Then
        MsgBox "Last Name is required",,"Required Field"
    ElseIf IsNull(MobileNo)Then
        MsgBox "Mobile Number is required",,"Required Field"
    ElseIf IsNull(MembershipType)Then
        MsgBox "Membership Type is required",,"Required Field"
    ElseIf IsNull(Username)Then
        MsgBox "Username is required",,"Required Field"
    ElseIf IsNull(Password)Then
        MsgBox "Password is required",,"Required Field"
    ElseIf IsNull(txtCardName)Then
        MsgBox "Card Name is required",,"Required Field"
    ElseIf IsNull(txtCardType)Then
        MsgBox "Card Type is required",,"Required Field"
    ElseIf IsNull(txtCardNumber)Then
        MsgBox "Card Number is required",,"Required Field"
    ElseIf IsNull(txtCVV)Then
        MsgBox "CVV is required",,"Required Field"
    ElseIf IsNull(txtExpiryDate)Then
        MsgBox "Expiry Date is required",,"Required Field"
    Else
       Msg ="Please select 'yes' to confirm membership"
       Style = vbYesNo + vbCritical
       Response = MsgBox(Msg, Style)
       If Response = vbYes Then
         DoCmd.Close
        ExitSub
       EndIf
       If Response = vbNo Then
          Me.Undo
          DoCmd.Close
          ExitSub
        EndIf
    EndIf
    Exit_ErrHandler:
    ExitSub
    ErrHandler:
        MsgBox Err.Description, vbCritical
        Err.Clear
    EndSub
    
    PrivateSub Username_AfterUpdate()
    
    Dim NewMember AsString
    Dim stLinkCriteria AsString
    NewMember =Me.Username.Value
    stLinkCriteria ="[Username] = "&"'"& NewMember &"'"
    IfMe.Username = DLookup("[Username]","tblMember", stLinkCriteria)Then
        MsgBox "This Username, "& NewMember &", already exists, please choose another username." _
        & vbCr & vbCr &"Please check name again or contact the Administrator", vbInformation,"Duplicate Name"
        Me.Undo
    EndIf
    EndSub
    


    Login:
    PrivateSub btnLogin_Click()
    
    If IsNull(Me.txtUsername)Then
        MsgBox "Please enter Username", vbInformation,"Username is required"
        Me.txtUsername.SetFocus
    ElseIf IsNull(Me.txtPassword)Then
        MsgBox "Please enter Password", vbInformation,"Password Required"
        Me.txtPassword.SetFocus
    Else
        If(IsNull(DLookup("[Username]","tblMember","[Username] ='"&Me.txtUsername.Value &"' And password ='"&Me.txtPassword.Value &"'")))Then
        MsgBox "Incorrect Username or Password"
        Else
        MsgBox "You have successfully logged in"
        DoCmd.OpenForm "frmHomepage"
        EndIf
    EndIf
    EndSub
    


    Update form
    PrivateSub btnUpdate_Click()
    OnErrorGoTo ErrHandler:
    If IsNull(MemberID)Then
       MsgBox "Please enter your personal details",,"Data Required"
    ElseIf IsNull(Title)Then
        MsgBox "Title is required",,"Required Field"
    ElseIf IsNull(FirstName)Then
        MsgBox "First Name is required",,"Required Field"
    ElseIf IsNull(LastName)Then
        MsgBox "Last Name is required",,"Required Field"
    ElseIf IsNull(MobileNo)Then
        MsgBox "Mobile Number is required",,"Required Field"
    ElseIf IsNull(MembershipType)Then
        MsgBox "Membership Type is required",,"Required Field"
    ElseIf IsNull(Username)Then
        MsgBox "Username is required",,"Required Field"
    ElseIf IsNull(Password)Then
        MsgBox "Password is required",,"Required Field"
    ElseIf IsNull(CardholderName)Then
        MsgBox "Card Name is required",,"Required Field"
    ElseIf IsNull(CardType)Then
        MsgBox "Card Type is required",,"Required Field"
    ElseIf IsNull(CardNumber)Then
        MsgBox "Card Number is required",,"Required Field"
    ElseIf IsNull(SecurityCode)Then
        MsgBox "CVV is required",,"Required Field"
    ElseIf IsNull(ExpiryDate)Then
        MsgBox "Expiry Date is required",,"Required Field"
    Else
       Msg ="Are you sure you want to update your membership?"
       Style = vbYesNo + vbCritical
       Response = MsgBox(Msg, Style)
       If Response = vbYes Then
         DoCmd.Close
        ExitSub
       EndIf
       If Response = vbNo Then
          Me.Undo
          DoCmd.Close
          ExitSub
        EndIf
    EndIf
    Exit_ErrHandler:
    ExitSub
    ErrHandler:
        MsgBox Err.Description, vbCritical
        Err.Clear
    EndSub
    


    My update form is the same as my register form I need to know what the correct code is for the update form
    I am really new to MS Access and VBA so do not have much understanding of how it works. I would greatly appreciate if you guys could help me out here

    Last edited by 2k7mmurtaza; 02-24-2018 at 11:46 AM.

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    This is not code! it's just a hint that might help you.
    PrivateSub btnLogin_Click()
    
    If IsNull(Me.txtUsername)Then
        MsgBox "Please enter Username", vbInformation,"Username is required"
        Me.txtUsername.SetFocus
    Exit Sub '<---------------------------
    End If
    
    If IsNull(Me.txtPassword)Then
        MsgBox "Please enter Password", vbInformation,"Password Required"
        Me.txtPassword.SetFocus
    Exit Sub  '<---------------------------
    End If
    
        If(IsNull(DLookup("[Username]","tblMember","[Username] ='"&Me.txtUsername.Value &"' And password ='"&Me.txtPassword.Value &"'")))Then
        MsgBox "Incorrect Username or Password"
    Exit Sub  '<---------------------------
    End If
    
        MsgBox "You have successfully logged in"
        DoCmd.OpenForm "frmHomepage"
    frmHomepage.init  '<---------------------------
    EndSub
    frmHomepage code Hint
    Sub Init()  '<---------------------------
    'Code to Clear all Form controls
    End Sub
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    hello

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    
    
    PHP Code:
    Yes
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •