Private Function ValidateLogin() As Integer
'====================================================================
' Comments: Compares both the Hard drive code, and the username and password, to ensure they are valid
' State of Code: Under Development
' Params :
' Returns : Integer
' Created : 11/18/2014 11:51 AM GB
' Modified:
'====================================================================
'TVCodeTools ErrorEnablerStart
On Error GoTo PROC_ERR
'TVCodeTools ErrorEnablerEnd
'define variables
Dim strHDSN As String
Dim strUser As String
Dim strPw As String
'confirm form is populated
Dim ctl As Control
For Each ctl In Me.Controls
Select Case ctl.ControlType
Case acTextBox
Debug.Print ctl.Value
If IsNull(ctl.Value) Then
MsgBox "Please ensure both the username and password are filled out" & vbCrLf & " then try again", vbInformation, ProgramTitle
ctl.SetFocus
GoTo PROC_EXIT
End If
End Select
Next
'populate variables
strHDSN = GetHDSN()
strUser = Me.txtUserName
strPw = Me.txtPassword
'open recordset to confirm variables
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Set dbs = OpenDatabase("CabProgram", dbDriverNoPrompt, True, ResizeMemo("~=FCR#SlNs2fcD^<zynh"))
strSQL = "SELECT * " & _
"FROM dbo_tblLogin " & _
"WHERE UserName = '" & strUser & "'"
Debug.Print strSQL
Set rst = dbs.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges)
With rst
'ensure username is valid
'.MoveLast
If .RecordCount < 1 Then
MsgBox "Username is not Valid" & vbCrLf & "Please try again", vbInformation
Me.txtUserName.SetFocus
GoTo PROC_EXIT
End If
'ensure password is valid
.MoveFirst
If rst("Password").Value = strPw Then
'continue
Else
MsgBox "Password is not Valid" & vbCrLf & "Please try again", vbInformation
Me.txtPassword.SetFocus
GoTo PROC_EXIT
End If
'check to ensure computer is the one registered
If Left(rst("HDSN").Value, Len(strHDSN)) <> strHDSN Then
MsgBox "This computer is not registered for this software" & vbCrLf & "Please Contact Atlanta Cabinet shop to setup", vbInformation
GoTo PROC_EXIT
End If
'close recordset
.Close
End With
Set rst = Nothing
dbs.Close
Set dbs = Nothing
'flag that everything was validated
ValidateLogin = 1
'TVCodeTools ErrorHandlerStart
PROC_EXIT:
Exit Function
PROC_ERR:
MsgBox Err.Description, vbCritical, Me.Name & ".ValidateLogin"
Resume PROC_EXIT
Resume
'TVCodeTools ErrorHandlerEnd
End Function