yes/no and dlookup

  • Thread starter Thread starter Sophy
  • Start date Start date
S

Sophy

Guest
here is the code i did, but its not working


If IsNull(DLookup("[SecurityPassword]", "TableSecurity", "[SecurityPassword] ='" & PW & "'")) Then

MsgBox "The password you typed is incorrect"

ElseIf IsNull(DLookup("[SecurityFormSiteInformationModify]", "TableSecurity", "[SecurityFormSiteInformationModify] = -1")) Then

MsgBox "You don't have permission to modify"


Else

MsgBox "You can now do the modifications"
SiteName.Locked = False
end if
-----------------------------------------------------------
Maybe this is not in a good section, but i would like to know, when you have a boolean value(yes/no) in a table, how do you write it in the code because the line elsif doesnt work, it always gives me the message"you don't have permission to modify", even if the checkbox in my table is checked.
Thanks
 
You wrote
<<
ElseIf IsNull(DLookup("[SecurityFormSiteInformationModify]", "TableSecurity", "[SecurityFormSiteInformationModify] = -1")) Then
>>
and you said this is always "true".

If SecurityFormSiteInformationModify is defined in a table as True/False, then you probably want to way "=False" instead of "-1".

RichM
 
yes, i have a field SecurityFormSiteInformationModify in my table tableSecurity, and in my code this is what i refer to.
If this field is checked in my table, i want the msgbox "you can now modify the information
if the field isnt checked, i want it to say "you dont have permission to modify"
but when i do it, it always gives me the same thing even if its checked or not.
I tried with the false and its the same thing
Thanks for your help
 
The syntax seems to be correct. A similar set-up on my PC works OK. It might be something to do with the way you set the yes/no field in the table. Presumably you only ever have one field ticked, or the expression wouldn't always return the right record anyway.

When do you update the yes/no field so that permissions can be granted?
 
OK, one more time.

You wrote
<<
ElseIf IsNull(DLookup("[SecurityFormSiteInformationModify]", "TableSecurity", "[SecurityFormSiteInformationModify] = -1")) Then
>>
and you said this is always "true".

Therefore:
The ElseIf is always true.
That means the IsNull expression is always true.
That means the DLookup function returned Null.

N'est pas ?

Therefore, the DLookup MUST be wrong in some way.

First check spelling. If you mis spell something, DLookup returns Null. It is not a "smart" function and it does not tell you what is wrong. It just returns Null.

Second, verify the "criteria" portion of the command. Try alternate forms of the criteria if necessary.

RichM
 
As I understand it:

If there are no records where a check box is TRUE, this expression evaluates to NULL and the error message is printed.

If there is one record where the checkbox is -1, the expression evaluates to -1 and the message is not printed.

If the value is always TRUE, why would it need to be evaluated in the first place?

I could be wrong - I frequently am...but the syntax works on my PC in that way.
 

Users who are viewing this thread

Back
Top Bottom