Vous êtes sur la page 1sur 3

Dim rs As Recordset

Set rs = New Recordset


rs.CursorLocation = adUseClient
rs.Open "Select * From Table WHERE No= '" & txtNo.Text & "'", con,
adOpenDynamic, adLockOptimistic
Set DataGrid1.DataSource = rs

Dim i
Dim Total As Double

For i = 0 To DataGrid1.ApproxCount - 1
Total =Total + DataGrid1.Columns(2).CellValue(DataGrid1.GetBookmark(i))
Next

txtTotal.Text =Total

Option Explicit

Private Sub cmdOK_Click()


'~~~ Add reference to Microsoft ActiveX Data Objects 2.x Library
'~~~ We are going to check the database for the entered username and
password. You need to make the necessary changes to suit your needs
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= " & App.Path & "\database.mdb;Persist Security
Info=False;Jet OLEDB:Database Password=myDBpassword;"
cn.Open
Set rs = New ADODB.Recordset
rs.Open "SELECT * FROM all_users WHERE user_name = '" & Trim$
(txtUserName.Text) & "' AND password = '" & txtPassword.Text & "'", cn,
adOpenForwardOnly, adLockReadOnly

If rs.EOF = False Then


Select Case LCase$(txtUserName.Text)
Case "admin"
myUser = user_Admin
Form1.Show
Unload frmLogin
Exit Sub
Case "guest"
myUser = user_Guest
Form1.Show
Unload frmLogin
Exit Sub
Case "normal"
myUser = user_Normal
Form1.Show
Unload frmLogin
Exit Sub
End Select
End If

MsgBox "Invalid Password, try again!", , "Login"


txtPassword.SetFocus
SendKeys "{Home}+{End}"

End Sub

Option Explicit
Dim user As String
Dim pass As String

Public LoginSucceeded As Boolean

Private Sub cmdExit_Click()


If MsgBox("Are you sure to close this Application?", vbQuestion + vbYesNo,
"System") = vbYes Then
End
End If
End Sub

Private Sub cmdLogin_Click()


user = "admin"
pass = "12345"

If txtUserName.Text = user Then


If txtPassword.Text = pass Then

MsgBox "Username and Password Accepted!", vbInformation, "Login"


'You may change this line here. call the form rather than displaying a
message box!

ElseIf txtPassword.Text = "" Then


MsgBox "Password Field Empty!", vbExclamation, "Login"
Else

MsgBox "Username and Password not Matched!", vbExclamation, "Login"


End If
ElseIf txtUserName.Text = "" Then
MsgBox "Username Field Empty!", vbExclamation, "Login"
Else
MsgBox "Invalid Username, try again!", , "Login"
txtPassword.SetFocus
End If
End Sub

Vous aimerez peut-être aussi