Hi all!

Originally Posted by
santon
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