sam
|
| Posted: 05/25/2004, 2:51 PM |
|
Hello,
I am trying to validate username & password from an access form.
Table: Login
Fields: Username, Password
Form: Login
Here is my code in the cmdSubmit click event in VB editior however, i am getting an error, "No value given for one or more required parameters"
Private Sub cmdSubmit_Click()
Dim cn As New ADODB.Connection
Dim rslogin As New ADODB.Recordset
Dim strqry As String
txtUserName.SetFocus
If Form_Login.txtUserName.Text = "" Then
MsgBox "Please enter your UserName", vbExclamation, "Invalid"
txtUserName.SetFocus
Else
txtPassword.SetFocus
If Form_Login.txtPassword.Text = "" Then
MsgBox "Please enter your password", vbExclamation, "Invalid"
txtPassword.SetFocus
Else
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\admissions.mdb;Jet OLEDB:Database Password=MyDbPassword;"
strqry = "Select * from Login where UserName=" & txtUserName
rslogin.Open strqry, cn, adOpenDynamic, adLockOptimistic
(IT ERRORS OUT FROM THE ABOVE LINE)
If rslogin.EOF Then
MsgBox "Invalid LoginID", vbCritical, "Invalid user"
rslogin.Close
cn.Close
ElseIf rslogin("Password").Value <> Trim(txtPassword) Then
MsgBox "Invalid user Name", vbCritical & vbOKOnly, "Invalid User"
rslogin.Close
cn.Close
Else
Form_Main.Visible = True
Unload Me
Me.Visible = False
End If
End If
End If
End Sub
|
|
|
 |
peterr
Posts: 5971
|
| Posted: 05/25/2004, 4:09 PM |
|
Possibly txtUserName should be in quotes. The SQL engine cannot execute syntax "WHERE UserName=abc"
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com |
 |
 |
Oper
Posts: 1195
|
| Posted: 05/25/2004, 4:39 PM |
|
as peterr said:
your SQL line must be like:
strqry = "Select * from Login where UserName= ' " & txtUserName & " ' "
(no spaces) i used space so ' could be easy to see.
_________________
____________________________
http://www.7bz.com (Free CMS,CRM Developed in CCS)
http://www.PremiumWebTemplate.com
Affiliation Web Site Templates
Please do backup first |
 |
 |
sam
|
| Posted: 05/26/2004, 8:25 AM |
|
Thanks. It fixed that part; however it still not actually validating when I test it. See below to where it stops: It not giving me an error but just stops at the msgbox..
Private Sub cmdSubmit_Click()
'Dim cn As New ADODB.Connection
Dim rslogin As New ADODB.Recordset
Dim strQry As String
txtUserName.SetFocus
If txtUserName.Text = "" Then
MsgBox "Enter your user name", vbOKOnly, "Empty"
Else
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\spatel\My Documents\admissions_b.bak;Jet OLEDB:Database Password=MyDbPassword;"
strQry = "Select * from Login where UserName= ' " & txtUserName & " ' "
rslogin.Open strQry, cn, adOpenDynamic, adLockOptimistic
If rslogin.EOF Then
MsgBox "Invalid LoginID", vbCritical, "Invalid user" ("IT STOPS HERE")
rslogin.Close
cn.Close
ElseIf rslogin("Password").Value <> Trim(txtPassword) Then
MsgBox "Invalid Password", vbCritical & vbOKOnly, "Invalid Password"
rslogin.Close
cn.Close
Else
IntUserId = CLng(txtPassword)
Load Form_Main
Form_Main.Visible = True
Form_Main.Label138.Caption = "IntUserid"
End If
End If
End Sub
|
|
|
 |
|