I'm trying to make a Username and password for the users who use the database. I want to make a form that has txtUserName , txtPassword and CmdOk. I have a table "Users" this table has two fields "UserName" and "Password".
what I've made is this, but it gives me an error. [No value given for 1 or more requiered parameteres]
Code:
Private Sub cmdOK_Click()
Dim sql1, sql2 As String
Dim db As ADODB.Recordset
Dim c1 As New ADODB.Connection
Set c1 = New ADODB.Connection
c1.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & "F:\Login Form.mdb"
Set db = New ADODB.Recordset
txtUserName.SetFocus
sql1 = "select * from users where UserName=" & txtUserName & " And "
txtPassword.SetFocus
sql2 = "Password=" & "'" & txtPassword & "'"
db.Open sql1 & sql2, c1, adOpenStatic, adLockOptimistic
If db.RecordCount = 0 Then
MsgBox "Please check your user name and password.", vbCritical, "L.S.S.I"
Else
DoCmd.OpenForm "Form_1", acNormal
Unload Me
End If
In sql1 you're forgetting the single quotes around txtUserName.
It wouldn't hurt to use txtUsername.Text (I'm guessing txtusername is the name of a textbox), or to set a string variable to the value in txtUserName and use that in the SQL instead.
Originally posted by salvelinus In sql1 you're forgetting the single quotes around txtUserName.
It wouldn't hurt to use txtUsername.Text (I'm guessing txtusername is the name of a textbox), or to set a string variable to the value in txtUserName and use that in the SQL instead.
Yeap, you are right mate the single quotes were the problems. But again it's not showing me the specified form that been requested to be showen after accpting the code. And the Login form it can't unloaded.
Code:
sql1 = "select * from users where UserName=" & "'" & txtUserName & "'" & " And "
In DoCmd.OpenForm, the windowmode is acWindowNormal, not acNormal (at least in Access 2000), and is the default anyway, so you don't need it (you also don't need the setfocus's above).