Make login form and get user id login to next form on visual basic

make a login form on visual basic it's so easy, but we can make some creation to make an user id can identifiying on the next form,
follow thats instruction:
1. create new project, choice vb enterprise edition control
2. go to Project, references, include that :
- visual basic for apps
- visual basic runtime object and procedure
- ole automation
- microsoft access 9 object library
- microsoft activex data objects 2.51 library
- microsoft DAO 3.51 objects library
- microsoft data binding collection
3. add 2 form, login form and main form
4. on the login form, add 2 text and 2 command button, the include this code :

Private Sub form_load()
'open connection to db
cn.Open ("Provider= Microsoft.Jet.OLEDB.4.0;Persist security info=False;Data Source=" & App.Path & "\database.mdb" & ";Jet OLEDB:Database;")
End Sub

Private Sub Command1_Click()
'access table user "tbuser", with "if id=text1 anf password=text2", if one of them not correct then login would fail
rs.Open "Select*from tbuser where id='" & Text1.Text & "' AND Password ='" & Text2.Text & "'", cn, 3, 3
If rs.EOF Then
'EOF yaitu end of field or if did'nt find
MsgBox "ID not registered or incorrect password", vbOKOnly + vbExclamation, "Attention !"
Text1.Text = ""
Text2.Text = ""
'clear text1 and text2
rs.Close
'close
Else
'-----------------------------------------------------------------
'use this code to get user login name
With rs
strid_user = !id 'set strid_user same as id login
End With
rs.Close 'close recordset
'============
Unload Me 'close form login
Main.Show 'show form main
End If
End Sub

Private Sub Command2_Click()
cn.Close
Unload Me
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
' Enter
If KeyAscii = 13 Then
'TAB
SendKeys vbTab
End If
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
'TAB
SendKeys vbTab
End If
End Sub

5. on the main form add timer1, label 10, label11, label12, then include this code :
Private Sub form_load()
'load eeverything here
'show day
Ahari = Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
SHari = Ahari(Abs(Weekday(Date) - 1))
'chow info
Label17 = "information of form"
'show user as login
Label10 = strid_user
'show date
Label12 = "" & SHari & ", " & Format(Date, "dd-mm-yyyy")
'call timer to show time
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
Label11 = Format(Time, "hh:mm:ss")
End Sub
6. make a module then include this :
Public cn As New ADODB.Connection
Public rs As New ADODB.Recordset

Public strid_user As String
7. dont forget include database.mdb on link download bottom, and run your project, use p id = a pass = a...

good luck

still dizzy, get project and learn...
download here : (use pass : do-stupid-things.blogspot.com
login as user_pass_do-stupid-things.blogspot.com.rar - 31 KB

0 komentar:

Post a Comment

Search This Blog

Recent Post

Popular Posts