Page 1 of 3 123 LastLast
Results 1 to 15 of 35
  1. #1
    santon's Avatar
    santon is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2020
    Posts
    44

    PIN number for employees

    Hello.


    I need a help with my checklist. It contains 5 different combo boxes, with a list of employees.
    After they select their name on the list, I need them to input the PIN number I have stored for them in another table to verify themselves.
    Click image for larger version. 

Name:	1.JPG 
Views:	37 
Size:	31.9 KB 
ID:	43607

    Operater_p has "after update" setting, macro that opens a small modal form, where you have to enter the pin.


    Click image for larger version. 

Name:	2.JPG 
Views:	38 
Size:	53.7 KB 
ID:	43609

    Button "Potvrdi PIN" has event procedure "On click", and this code:

    Code:
    Option Compare Database
    
    
    
    Private Sub potvrda_pin_Click()
    
    
        Dim Username As String
        Dim strSQL As String
        Dim strMsg As String
        Dim dbs As DAO.Database
        Dim rst As DAO.Recordset
        Dim password_check As Integer
        
        Username = Form_CO_pakiranje_SD14.operater_p
        Set dbs = CurrentDb()
        strSQL = "SELECT password FROM Evidencija_radnika WHERE ime_prezime = '" & Username & "';"
        Set rst = dbs.OpenRecordset(strSQL)
        password_check = rst![Password]
        rst.Close
        dbs.Close
        If (Form_CO_pakiranje_SD14!potpis_operater) <> password_check Then
        strMsg = Username & ", niste unijeli tocan PIN!"
            MsgBox strMsg
            Form_CO_pakiranje_SD14!potpis_operater = ""
            Else
            Form_CO_pakiranje_SD14!potpis_operater = password_check
            strMsg = Username & ", uspjesno potvrden PIN!"
            MsgBox strMsg
        End If
    
    
    End Sub

    It shows no error, but it doesn't work as it supposed to.
    If you click "Potvrdi PIN" first time it returns it's wrong number, and if you click again then it says that is confirmed number.
    Can you help me fix this?
    And possibly if I can add something so if it is good PIN, then close this form "potpis" and maybe paint the operater_p in green (conditional formatting maybe?)

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    Code:
    sub btnEnter_click()
    if IsGoodEmpPin(txtEmpNum, txtPin) then
      'let user in
    else
       msgbox "Invalid"
    endif
    
    
    
    
    function IsGoodEmpPin(pvEmpNum,pvPin) as boolean
    on error resume next
       IsGoodEmpPin =dLookup("[EmpID],"tEmployees","[EmpID]='" & pvEmpNum & "' and [Pin]='" & pvPin & "'") = pvEmpNum
    end function

  3. #3
    santon's Avatar
    santon is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2020
    Posts
    44
    Quote Originally Posted by ranman256 View Post
    Code:
    sub btnEnter_click()
    if IsGoodEmpPin(txtEmpNum, txtPin) then
      'let user in
    else
       msgbox "Invalid"
    endif
    
    function IsGoodEmpPin(pvEmpNum,pvPin) as boolean
    on error resume next
       IsGoodEmpPin =dLookup("[EmpID],"tEmployees","[EmpID]='" & pvEmpNum & "' and [Pin]='" & pvPin & "'") = pvEmpNum
    end function
    Excuse me, can you be a little more specific? I am really a noob at programming and I don't fully understand what you wrote.
    Do I need it to type in your code with mine or only yours? Can you explain a little bit what I need to change




    Also, I had an idea and I don't know can it work, but seems a little bit easier. Can I create a text box (field for entering the pin number) and combo box, which will have list of employees, compare names with PIN and then show the full name of the employee (set on locked so it can't be edited)
    Click image for larger version. 

Name:	PIN.png 
Views:	34 
Size:	2.7 KB 
ID:	43612

  4. #4
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Please review the updates code below:

    Code:
    Option Compare Database
    Option Explicit  'always use
    
    
    
    
    Private Sub potvrda_pin_Click()
    
    
    
    
        Dim Username As String
        Dim strSQL As String
        Dim strMsg As String
        Dim dbs As DAO.Database
        Dim rst As DAO.Recordset
        Dim password_check As Integer
        
        Username = Form_CO_pakiranje_SD14.operater_p
        Set dbs = CurrentDb()
        strSQL = "SELECT password FROM Evidencija_radnika WHERE ime_prezime = '" & Username & "';"
        Set rst = dbs.OpenRecordset(strSQL)
        password_check = rst![Password]
        rst.Close
        dbs.Close
        If (Form_CO_pakiranje_SD14!potpis_operater) <> password_check Then  'the form in bold red should be the modal one not the one with the combos
            strMsg = Username & ", niste unijeli tocan PIN!"
            MsgBox strMsg
            Form_CO_pakiranje_SD14!potpis_operater = Null    ' was ""
        Else
            'Form_CO_pakiranje_SD14!potpis_operater = password_check  'not needed
            strMsg = Username & ", uspjesno potvrden PIN!"
            MsgBox strMsg
            Form_CO_pakiranje_SD14.operater_p.BackColor=RGB(0,255,0)  'green back color
            DoCmd.Close acForm, Me.Name
        End If
    
    
    
    
    End Sub
    RGB(0,255,0)
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  6. #6
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    A couple of other VBA corrections:
    Code:
    Option Compare Database
    Option Explicit  'always use
    
    Private Sub potvrda_pin_Click()
        Dim Username As String
        Dim strSQL As String
        Dim strMsg As String
        Dim dbs As DAO.Database
        Dim rst As DAO.Recordset
        Dim password_check As Integer
        
        Username = Form_CO_pakiranje_SD14.operater_p
        Set dbs = CurrentDb()
        strSQL = "SELECT password FROM Evidencija_radnika WHERE ime_prezime = '" & Username & "';"
        Set rst = dbs.OpenRecordset(strSQL)
        password_check = rst![Password]
        rst.Close
        dbs.Close    '<-- You did not "Open" dbs, so you should NOT "Close" it.
        If (Form_CO_pakiranje_SD14!potpis_operater) <> password_check Then  'the form in bold red should be the modal one not the one with the combos
            strMsg = Username & ", niste unijeli tocan PIN!"
            MsgBox strMsg
            Form_CO_pakiranje_SD14!potpis_operater = Null    ' was ""
        Else
            'Form_CO_pakiranje_SD14!potpis_operater = password_check  'not needed
            strMsg = Username & ", uspjesno potvrden PIN!"
            MsgBox strMsg
            Form_CO_pakiranje_SD14.operater_p.BackColor=RGB(0,255,0)  'green back color
            DoCmd.Close acForm, Me.Name
        End If
    
    'Clean up
        Set rst = Nothing    '<-- Added     You should Destroy the pointer after the record set is closed
        Set dbs = Nothing   '<-- Added     You should Destroy the pointer
    
    End Sub

  7. #7
    santon's Avatar
    santon is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2020
    Posts
    44
    Quote Originally Posted by Gicu View Post
    Please review the updates code below:

    Code:
    Option Compare Database
    Option Explicit  'always use
    
    
    
    
    Private Sub potvrda_pin_Click()
    
    
    
    
        Dim Username As String
        Dim strSQL As String
        Dim strMsg As String
        Dim dbs As DAO.Database
        Dim rst As DAO.Recordset
        Dim password_check As Integer
        
        Username = Form_CO_pakiranje_SD14.operater_p
        Set dbs = CurrentDb()
        strSQL = "SELECT password FROM Evidencija_radnika WHERE ime_prezime = '" & Username & "';"
        Set rst = dbs.OpenRecordset(strSQL)
        password_check = rst![Password]
        rst.Close
        dbs.Close
        If (Form_CO_pakiranje_SD14!potpis_operater) <> password_check Then  'the form in bold red should be the modal one not the one with the combos
            strMsg = Username & ", niste unijeli tocan PIN!"
            MsgBox strMsg
            Form_CO_pakiranje_SD14!potpis_operater = Null    ' was ""
        Else
            'Form_CO_pakiranje_SD14!potpis_operater = password_check  'not needed
            strMsg = Username & ", uspjesno potvrden PIN!"
            MsgBox strMsg
            Form_CO_pakiranje_SD14.operater_p.BackColor=RGB(0,255,0)  'green back color
            DoCmd.Close acForm, Me.Name
        End If
    
    
    
    
    End Sub
    RGB(0,255,0)



    Thank you for your answer. I tried, but it doesn't work :/ I must have done something wrong
    Click image for larger version. 

Name:	Untitled.jpg 
Views:	26 
Size:	120.0 KB 
ID:	43625

  8. #8
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    operater_p should be the name of your control, not the name of the field

  9. #9
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    You can also try Forms!CO_pakiranje_SD14!operater_p.BackColor if operater_p is indeed the control name.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  10. #10
    santon's Avatar
    santon is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2020
    Posts
    44
    This is not gonna work. Tried it multiple times, returns various errors, I'm gonna leave that idea with modal form.
    This one is working just fine, I just wanted to make it more interesting.

    Ok, I will use this code to do this on the pictures below, I just want after PIN is successfully entered (like on the picture)
    to make field operater_p and potpis_operater disabled, to make the others aware that "OPERATER" is done with his part of this checklist.
    Can you help me with that?
    Also thank you for your help so far

    Code:
    Option Compare DatabaseOption Explicit
    
    
    
    
    Private Sub potpis_operater_AfterUpdate()
    Dim Username As String
        Dim strSQL As String
        Dim strMsg As String
        Dim dbs As DAO.Database
        Dim rst As DAO.Recordset
        Dim password_check As Integer
        
        Username = Form_CO_pakiranje_SD14.operater_p
        Set dbs = CurrentDb()
        strSQL = "SELECT password FROM Evidencija_radnika WHERE ime_prezime = '" & Username & "';"
        Set rst = dbs.OpenRecordset(strSQL)
        password_check = rst![Password]
        rst.Close
        
        If CInt(Form_CO_pakiranje_SD14!potpis_operater) <> password_check Then
        strMsg = Username & ", niste unijeli tocan PIN!"
            MsgBox strMsg
            Form_CO_pakiranje_SD14!potpis_operater = ""
            Else
            Form_CO_pakiranje_SD14!potpis_operater = password_check
            strMsg = Username & ", uspjesno potvrden PIN!"
            MsgBox strMsg
        End If
        
        Set rst = Nothing
        Set dbs = Nothing
        
    End Sub
    Click image for larger version. 

Name:	2.JPG 
Views:	26 
Size:	19.7 KB 
ID:	43630 Click image for larger version. 

Name:	potpis.JPG 
Views:	26 
Size:	26.6 KB 
ID:	43629

  11. #11
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    If I understand you correctly I think the easiest way to achieve that is to add in the Current event of the form checks to see if both text boxes are filled in then disable them:

    Code:
    
    
    Code:
    If Not IsNull(Me.operater_p) And Not IsNull(Me.potpis_operater) Then
    Me.operater_p.Enabled =False
    Me.potpis_operater.Enabled=False
    End If
    'similar checks for the other pairs
    


    Cheers,
    Vlad

    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  12. #12
    santon's Avatar
    santon is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2020
    Posts
    44
    Quote Originally Posted by Gicu View Post
    If I understand you correctly I think the easiest way to achieve that is to add in the Current event of the form checks to see if both text boxes are filled in then disable them:

    Code:
    
    
    Code:
    If Not IsNull(Me.operater_p) And Not IsNull(Me.potpis_operater) Then
    Me.operater_p.Enabled =False
    Me.potpis_operater.Enabled=False
    End If
    'similar checks for the other pairs
    


    Cheers,
    Vlad

    It disabled both fields, but when I want to add new record it is also disabled

    Click image for larger version. 

Name:	lock 1.JPG 
Views:	26 
Size:	14.4 KB 
ID:	43632


    Click image for larger version. 

Name:	lock 2.JPG 
Views:	26 
Size:	13.0 KB 
ID:	43633

  13. #13
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    You need to enable them:
    Code:
    If Not IsNull(Me.operater_p) And Not IsNull(Me.potpis_operater) Then
           Me.operater_p.Enabled =False
           Me.potpis_operater.Enabled=False
    Else
          Me.operater_p.Enabled =True
          Me.potpis_operater.Enabled=True
    End iF
    Cheers,
    Vlad
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  14. #14
    santon's Avatar
    santon is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2020
    Posts
    44
    Quote Originally Posted by Gicu View Post
    You need to enable them:
    Code:
    If Not IsNull(Me.operater_p) And Not IsNull(Me.potpis_operater) Then
           Me.operater_p.Enabled =False
           Me.potpis_operater.Enabled=False
    Else
          Me.operater_p.Enabled =True
          Me.potpis_operater.Enabled=True
    End iF
    Cheers,
    Vlad
    It works only when I press the button to "add a new record", when I return to view the previous one, it is disabled.
    But while I enter PIN and it is confirmed, I can still edit everything.

    Click image for larger version. 

Name:	1.JPG 
Views:	28 
Size:	24.0 KB 
ID:	43634

    Click image for larger version. 

Name:	Capture.JPG 
Views:	29 
Size:	14.5 KB 
ID:	43635

  15. #15
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Hi all!

    Quote Originally Posted by santon View Post
    It shows no error, but it doesn't work as it supposed to.
    Form_CO_pakiranje_SD14 is the class of then form "CO_pakiranje_SD14", not the running instance of this class and, in this case of reference, code works accidentally. You have to use a proper way of reference to a loaded form, like:

    • Me (for the “potpis” form)
    • Forms("CO_pakiranje_SD14")
    • Forms!CO_pakiranje_SD14


    Please try this version of your potvrda_pin_Click procedure and check if it works properly (I didn’t):
    Code:
    Private Sub potvrda_pin_Click()
        Dim Username As String
        Dim strSQL As String
        Dim strMsg As String
        Dim dbs As DAO.Database
        Dim rst As DAO.Recordset
        Dim password_check As Variant  'Variant for the case of Null password.
        Dim frmSD14 As Form            'Variable for the form "CO_pakiranje_SD14"
    
        With Me.pin_operater 'Check the user entry.
            If Len(.value & "") = 4 And IsNumeric(.value & "") Then
                'Correct pin entry. Keep going.
            Else
                'Incorrect pin entry. Display a relevant message here.
                'I often use the ValidationText of the control to keep the corresponding message.
                MsgBox .ValidationText, vbExclamation, Me.potvrda_pin.Caption
                .SetFocus
                Exit Sub
            End If
        End With
    
        On Error Resume Next
        Set frmSD14 = Forms!CO_pakiranje_SD14   'Set a pointer to the form "CO_pakiranje_SD14" (if is loaded).
        On Error GoTo ErrHandler
    
        If Not frmSD14 Is Nothing Then  'If not is loaded frmSD14 is Nothing.
            Username = Nz(frmSD14.operater_p, "")    'Could be Null.
            If Len(Username) = 0 Then   'Check if there is a name in operater_p.
                '[operater_p] is empty! Display a relevant message here.
            Else
                Set dbs = CurrentDb()
                strSQL = "SELECT password FROM Evidencija_radnika WHERE ime_prezime = '" & Username & "';"
                Set rst = dbs.OpenRecordset(strSQL)
                If rst.BOF And rst.EOF Then
                    'User not found! Display a relevant message here.
                Else
                    password_check = rst![Password]    'Could be Null.
                    If IsNull(password_check) Then
                        'password/pin has not been set! Display a relevant message here.
                    Else
                        If (Me.pin_operater) <> password_check Then
                            strMsg = Username & ", niste unijeli tocan PIN!"
                            MsgBox strMsg, vbExclamation, Me.potvrda_pin.Caption
                            frmSD14.potpis_operater = Null
                        Else
                            frmSD14.potpis_operater = password_check
                            strMsg = Username & ", uspjesno potvrden PIN!"
                            MsgBox strMsg, vbInformation, Me.potvrda_pin.Caption
                            DoCmd.Close acForm, Me.Name
                        End If
                    End If
                End If
            End If
        End If
    ExitHere:
        On Error Resume Next
        rst.Close
        Set rst = Nothing
        Set dbs = Nothing
        On Error GoTo 0
        Exit Sub
    ErrHandler:
        MsgBox Err.Description, vbExclamation, Me.potvrda_pin.Caption
        Resume ExitHere
    End Sub
    Cheers,
    John

Page 1 of 3 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Employees Example
    By Mickjav in forum Code Repository
    Replies: 1
    Last Post: 07-06-2020, 12:35 PM
  2. Replies: 11
    Last Post: 04-03-2020, 10:36 PM
  3. How to assign employees
    By rjayb118 in forum Access
    Replies: 5
    Last Post: 09-26-2016, 05:19 PM
  4. Replies: 1
    Last Post: 01-31-2014, 11:03 PM
  5. Replies: 1
    Last Post: 08-23-2013, 07:53 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