hello can you please help me and please correct my code if this is wrong. please also check my cursor type if it is correct..hoping for your positive responds...

Option Explicit

Public con As ADODB.Connection
Public user_rs As ADODB.Recordset
Public cmd As ADODB.Command
Public m_user As String
Public m_pass As String
Public sql As String


Private Sub Form_Load()

Set con = New ADODB.Connection
Set user_rs = New ADODB.Recordset
Set cmd = New ADODB.Command


With con
  .ConnectionString = "provider = microsoft.jet.oledb.4.0; data source =" & App.Path & "\project.mdb"
  .Open
End With


Me.Move (Screen.Width - Width) \ 2, (Screen.Height - Height) \ 2

End Sub



Private Sub cmdlog_Click()





m_user = Trim(txtuser.Text)
m_pass = Trim(txtpass.Text)

If user_rs.State = adStateOpen Then
  user_rs.Close
  End If


sql = "select * from security where user_name = '" & m_user & "' and user_pass = '" & m_pass & "'"
user_rs.Open sql, con, adOpenDynamic, adLockPessimistic



If user_rs.BOF = True And user_rs.EOF = True Then
  MsgBox "Sorry username and password cannot be found..Please
Register if you don't have Account", vbCritical, "REGISTER FIRST..."
  Exit Sub
  
Else
 
   Unload Me
   Form6.Show
   End If
   

End Sub
Private Sub cmdexit_Click()
Unload Me
End Sub

Private Sub lblsign_Click()
Form16.Show
Unload Me
End Sub

Your looks ok (i did not check in IDE )

Are you getting any error from your code ?

Please check the auto generated code in inbuilt wizard in VB 6 .

thank you for the reply sir,i just want to let you see my code if this is in proper logic in making log-in password...and also using cursortype.hoping for your positive responds.

you can also try this

take a count of records by passing the user name and password
if count returns 1 then proceed further else re-prompt for the correct login credentials.

this will be faster as you do not have top loop through the recordset.

hello sir thank you for the reply..
i don't know the syntax can you show me what you mean sir..hoping for your positive responds..

IDE = Integrated Design Environment
Yes you do know about the recordcount as I showed you this before...

debasisdas, presently jemz does not need to loop through the recordset looking for a match as the username/password are provided as part of the query in the where clause...

jemz, the pessimistic locking is how the database will react when you use the edit/addnew method of the recordset. Pessimistic locks the page when you execute the edit/addnew statement while optimistic locks the page when the update method is executed. So...

rs.fields("fieldname") = somevalue 'pessmistic locks here
rs.update 'optimistic locks here

So presently, since you are not editing the returned recordset, it does not matter.

Good Luck

i suggested count for faster processing and there will no addition check for null recordset (in case there is no matching record).

hello sir correct me if i am wrong.. is this what you mean?

sql = "select * from security where user_name = '" & m_user & "' and user_pass = '" & m_pass & "'"
user_rs.Open sql, con, adOpenDynamic, adLockPessimistic


If user_rs.RecordCount = 0 Then

  MsgBox "Sorry username and password cannot be found..Please Register if you don't have Account", vbCritical, "REGISTER FIRST..."
  Exit Sub
  
Else
 
   Unload Me
   Form6.Show
   End If

hello sir goog morning..

correct me if i am wrong sir..is this what you mean recordcount sir..hoping for your positive responds...

sql = "select * from security where user_name = '" & m_user & "' and user_pass = '" & m_pass & "'"
user_rs.Open sql, con, adOpenDynamic, adLockPessimistic


If user_rs.RecordCount = 0 Then


  MsgBox "Sorry username and password cannot be found..Please Register if you don't have Account", vbCritical, "REGISTER FIRST..."
  Exit Sub
  
Else
 
   Unload Me
   Form6.Show
   End If

Edited 6 Years Ago by jemz: n/a

strSQL = "SELECT COUNT(idfield) AS THECOUNT FROM tablename WHERE field1 = '" & sometextvalue & "' AND field2 = '" & someothertextvalue & "'"
rs.open strSQL, ...
If rs.fields("THECOUNT") = 0 Then
  MsgBox '...

is what debasisdas meant...

and debasisdas,

>this will be faster as you do not have top loop through the recordset.

hence my reply previously...

Good Luck

hello sir thank you for the reply..here's the code sir please correct me if i am wrong...i thought sir,the count use for determining how many fields that i have in my database...thank you again sir ....hoping for your positive responds.

sql = "SELECT COUNT(user_name) AS THECOUNT FROM security WHERE user_name = '" & m_user & "' and user_pass = '" & m_pass & "'"
 user_rs.Open sql, con, adOpenDynamic, adLockPessimistic


If user_rs.user_name("THECOUNT") = 0 Then

  MsgBox "Sorry username and password cannot be found..Please Register if you don't have Account", vbCritical, "REGISTER FIRST..."
  Exit Sub
  
Else
 
   Unload Me
   Form6.Show
   End If

Edited 6 Years Ago by jemz: n/a

oki sir thank you for the reply..sir what is the purpose of AS THECOUNT?..
and also this user_rs.fields("THECOUNT")..for what is this sir ("THECOUNT")..i really don't know for this...please help me to explain this sir..hoping for your positive responds....

That is the alias for the field COUNT(user_name) . If not user Database will return COUNT(user_name) as the field which may create some problem later on because of the special characters.

hi jemz,
To be simple here "THECOUNT" used by vb5prgrmr and debasisdas in something like loading new field which isn't in your database. For example you are in Group A and your spouse is in Group B. Now its like both you and your spouse were pulled out of Group A and Group B as New Family giving new name like 'Jemz Family'.

If you are really confused about that then try below code which will do the same.

strSQL = "SELECT * FROM tblUsers WHERE Username LIKE '" & txtUsername.Text & "' AND Password LIKE '" & txtPassword.Text & "'"
    RST.Open strSQL, CON, adOpenForwardOnly, adLockOptimistic

    If RST.EOF = False Then
    Unload Me
    frmMain.Show
    Else
    MsgBox "You have entered Invalid Username or Password.", vbCritical, "Invalid Entry"
    txtUsername = ""
    txtPassword = ""
    txtUsername.SetFocus
    End If

Thanks

thank you for the reply sir... so you mean sir that THECOUNT is variable..so i can change that to JEM.am i correct sir?

hello sir thank you for the reply...thank you for enlighten my mind..more power to you....

That is just an column alias for COUNT(user_name). Yes you can use your own name. You can use anything as an alias so far it supports the oracle naming conventions.

thank you sir debasisdas, more power to you...thank you for helping me and to all who reply in this thread and teaching me...thank you to all of you...more power...

sir, i have some question for this..how to put text on my textfield like..the daniweb login and password...inside the textfield there is username and inside the password field there is password...please help me sir how to put text on the textfield hoping for your positive responds.

Jemz, are you talking about automatically loading the users username and password when the application started. In other words, the user selected an option to "remember me" or "automatically Log Me In" scenario?

hello, sir thank you for the reply sir..no sir..i want sir just like the daniweb before you log-in there is a text"USER NAME" and "PASSWORD"..try to look at that sir...about the remember me option sir can you also help me on that i have no idea on that code...hoping for your positive responds...

hello sir thank you for the reply sir i will try this sir.....ahm sir is this possible also on the flexgrid sir?...question also for the flexgrid sir can i also make it transparent like the label....hoping for your positive responds..more power to you sir....

hello sir thank you for the reply.. i will try this sir and i will write again if i have doubt thank you for helping me sir..more power to you.....

hello sir AndreRet, sir I look at the program it's amazing that i could not beleive it.. is this the code of the daniweb sir? sir thank you also for putting comment on it and it really helps me sir...more power to you sir. thank you also for giving me idea on the log-in password..i will write you again sir..hoping for your positive responds...

Only a pleasure jemz.

The code is not the same as Daniweb, I am sure they have done it differently, but the basics is the same.

Happy coding...

This article has been dead for over six months. Start a new discussion instead.