Form3.Adodc1.RecordSource = "select * from login where username = '" + Text1.Text + "'"
   Form3.Adodc1.Refresh
If Form3.Adodc1.Recordset.EOF = False Then
If (Text2.Text = Form3.Adodc1.Recordset.Fields("password")) Then
    MsgBox "login success"
    Unload Me
Else
    MsgBox "invalid pasword"
    Text1.Text = ""
    Text2.Text = ""
    Text1.SetFocus
    Form2.Refresh
    End If
Else
    MsgBox "invalid username"
    Text1.Text = ""
    Text2.Text = ""
    Text1.SetFocus
    Form2.Refresh
End If
If Form3.Adodc2.Recordset.EOF = False Then
    msg = MsgBox("Go to Inventory?", vbYesNo, "WELCOME")
If msg = vbYes Then
    Form2.Hide
    Form5.Show
Else
    Form2.Hide
    Form3.Show
End If
End If

....this is my login command code.....


QUESTION : can someone help me with this...the logic of my system is if admin was login he can access all forms he can create new user he can access inventory but if a regular user login he can only access inventory he can't access the form which can create another user ...PLEASE HELP ME THIS IS A VB6 SYTEM....I NEED THIS...ASAP....i will attach my files in here so that you can see all my codes and my whole system....

Edited 5 Years Ago by ~s.o.s~: Added code tags; please learn to use them.

As I couldnt open your attachment. So in logical way I would say.
1.do not give other users access to userform.
2.even if you want to give access for changing password... disable "add new user" option for ordniary user

Happy COding!!

Edited 3 Years Ago by happygeek: fixed formatting

but what is the code of your logic..sample is admin was login all option are enable..but what if a regular user login the only access he has is the inventory form...can you tell what code should i use to manage that....i can't do that in if/else statement..can you please tell me...pls..pls...plss...

In the login table stare a flag value, which specifies if the ligin use is a normal user or an admin.

Based on that flag value you can enable / disable other dependent forms.

Try:

Option Explicit


Dim passattemp As Double
Dim db As ADODB.Connection
Dim rs As ADODB.Recordset


Private Sub cmdLogin_Click()

Dim User As String
Dim CurrentPosition As String

    
If Text1.Text = "" And Text2.Text = "" Then
    
    
    MsgBox "Data required, please enter a valid username and password!", vbCritical, "Log-in Error"
            
            Text1.Text = ""
            Text2.Text = ""
            Text1.SetFocus
 Else
    
 
    Set db = New ADODB.Connection
        db.CursorLocation = adUseClient
        db.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source=" & App.Path & "\DATABASENAME.mdb"
    
    Set rs = New ADODB.Recordset
        rs.Open "select * from TABLENAME where Username(name of ur field of usernames) = '" & Text1 & "'", db, adOpenStatic, adLockOptimistic

            
                    
If Not rs.EOF Then
        

    If Text2.Text = rs!Password And Text1.Text = rs!UserName Then 
    MsgBox "Welcome to The System!", vbInformation, "Log-in Success"
    
    
                    User = Text1.Text
                    CurrentPosition = rs.Fields("UserType") 

			' UserType is the Table Field which has values of admin or user
                        'Depends on your Table Fields - change
			                        
                    With Form3
                    
                                        
                   If rs.Fields("UserType").Value = "Administrator" Then
                        
                            'all command buttons are set to Enable = True
			    'your codes here
                        
                        Else
                            'all command buttons are set to Enable to False except inventory part and exit
			    'your codes here
                            
                            
    End If
                              
        End With
        Unload Me
        Form3.Show
    
    Else
        passattemp = passattemp + 1
        If passattemp = 3 Then
            MsgBox "You are not an authorized user. Program will close.", vbCritical, "Log In Error"
        End
	
	'Err message if the user failed to login with a valid username and pass 3 times        

            
    Else
        MsgBox "Password incorrect." & vbCrLf & " Attempt left " & 3 - passattemp & "", vbExclamation, "Log In Error"
            txtPass.Text = ""
            txtPass.SetFocus

	'Err message if the password entered isn't on the Password Field of the Database Table

        End If
    End If
            
    Else
        MsgBox "This user does not exist.", vbCritical, "Log In Error"

	'Err message if the user enters a record either username or password that is not on the database

            Text1.Text = vbNullString
            Text2.Text = vbNullString
            Text1.SetFocus
    End If
 End If
        
Set rs = Nothing

Exit Sub

Err:
MsgBox Err.Description, vbCritical

End Sub

tnx u so much..Mr. Abelingaw your code help me so much...tnx again..by the way i have one last question for you about coding...here is the scenario...in my inventory system i have database and it's fields are "Item Number,Description,Last Week Stocks,Deliveries,Total Stocks,Total Withdrawal and Current Stock...this is my logic if adding new stock it will add to 'Current Stock' and to 'Total Stocks' and if withdrawing stocks 'it will add to 'Total Withdrawal' and the value of the 'Last Week Stock' will update every week...can you please give me another code about my logic...
"""THE HARDEST PART OF MY PROBLEM IS EDITING THE VALUE OF THE DATABASE"""
can u please give me a code on how to edit the database value...hope you will reply on my problem because i need the finish program tomorrow...please help me...by the way thanks again for the login code it really helps....

Please mark thread as solved if we help you.

Create another thread if you have further questions.

This question has already been answered. Start a new discussion instead.