Command OpenQuery

  • Thread starter Thread starter fabio
  • Start date Start date
F

fabio

hi everyone,

I just started playing with Access and I have a problem.
I created a log in form for entering User.ID and Password and I would
like a button to verify the log in and eventually opening tha main form
of the application.
I wrote a simple query to verify is the values entered in the ID and
Password fields on th Log- In form are present in the corrtect User table.
What I would like to do is open the query if there is a result, then the
user and password is correct and the main form is opened, otherwise the
user is not allowd to enter. I don't know how to check if the result of
the query is empty or not, I dont know what ius the object returned by
the command OpenQuery.
Here what I wrote in VBA

DoCmd.OpenQuery "Query_Log_In"
if IsNull " the recordset returned by the query"
then MsgBox "please enter the right user Id and password"
else DoCmd.OpemForm " Main"

Sorry for being so long in explanation.
Could you please suggest what I have to write on the if condition?
thanks in advance

Fabio
 
In the Click event of your combo box ...

Dim rst As ADODB.Recordset
Dim lngTheCount As Long

Set rst = New ADODB.Recordset
rst.ActiveConnection = CurrentProject.Connection
rst.Open "SELECT Count(*) AS TheCount FROM YourTable WHERE YourUserNameField
= '" & Me!YourUserNameControl & "' AND YourPasswordField = '" &
Me!YourPasswordControl & "'"
lngTheCount = rst.Fields("TheCount")
rst.Close
If lngTheCount = 0 Then
'log in fails
Else
'log in succeeds
End If

You do realise that equivalent functionality is built-in to Jet, and if you
don't use Jet's built-in security features, anyone can by-pass your form and
read the names and passwords in the table?

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
You can try:

If DCount("*","Query_Log_In") = 0 Then
MsgBox "please enter the right user Id and password"
Else
DoCmd.OpemForm "Main"
End If

However, this is not secure as there are ways that users can bypass your
LogIn Form. Think of this as an identification process, _not_ security
process. If you want proper security, use Access security.
 
Back
Top