btw, one thing that may help you understand the use of a domain aggregate
function in a macro Condition, is to be sure you understand how a condition
works.
the expression in a Condition column is always an equation (or more than
one, but we won't get into complex expressions), that evaluates to True or
False. think of it as making a statement, like "It's 70 degrees outside
right now." Sometimes that statement is true, sometimes it isn't. if you
write an equation, like
2+2 = 1+3
Access calculates the expression on the left side of the equation (2+2), and
returns 4. then Access calculates the expression on the right side of the
equation (1+3), and returns 4. then it evaluates the expression
4=4
as being a True or False statement. the statement evaluates to True, and so
the macro action runs. of course, hard-coded values are what they are, so 4
will always equal 4. but when you replace a hard-coded value with domain
aggregate function, for instance, then the statement may be True or False,
depending on what the function returns. in the statement
DCount(1, "tblUsers", "[UserName] = '" & [UserName] & "' And [Password] = '"
& [Password] & "'") > 0
Access first runs the DCount() function.
DCount(1, "tblUsers", "[UserName] = '" & [UserName] & "' And [Password] = '"
& [Password] & "'")
if no records that match the criteria are found in the domain (a table, in
this case), then the function returns zero (0). so the equation
0 > 0
is evaluated, and of course it's False. but if one or more records that
match the criteria is found, then the DCount() function counts the matching
records (of course) and returns that count. so the equation
1 > 0
(or 2 > 0, or however many records are found)
is evaluated, and of course any positive number is greater than zero, so the
expression is True. and the macro action runs.
hth
Karen said:
Thank you for the explanation. The D functions are still new to me and I am
trying to learn more and your explanation helped alot. I will give it a go.
tina said:
i understand that, hon. the expression
DCount(1, "tblUsers", "[UserName] = '" & [UserName] & "' And [Password] = '"
& [Password] & "'") > 0
all goes on one line in the macro Condition column. the expression evaluates
to True if a matching record is found in the table, and evaluates to False
if no record is found. when the condition = True, then the macro action will
run.
one thing to note is that if two users happen to have the same name, and
happen to choose the same password (not likely, but not impossible unless
you've disallowed duplicate values in those fields at the table level), then
the DCount() expression will return True and the macro action will run -
with nothing to stop one user from logging in as the other.
hth
Sorry, I may not have been clear. I do not want to count the records, I
want
to verify that the user has entered the correct username and password into
the login form. If they have, the switchboard will open.
:
try
DCount(1, "tblUsers", "[UserName] = '" & [UserName] & "' And [Password]
= '"
& [Password] & "'") > 0
hth
Hi,
I have a form which the user enters their UserName in an unbound text
box
and Password in another unbound text box. I want the macro to verify
what
was entered in these two text boxes against information in the user
table.
If the UserName and Password match, then the database will open the
switchboard. I have the following condition:
[UserName]=DLookUp("[UserName]","tblUsers") And
[Password]=DLookUp("[Password]","tblUsers")
The macro is only reading the first row of data in the UserTable.
When I
enter that UserName and Password, the Switchboard opens. If I enter
another
UserName and Password that have been entered in the table, it does not
work.
Please help!!