Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2013
    Posts
    1

    Unanswered: Dlookup() If Statement not supplying results

    Hi there!

    I really hope that someone can help me, and forgive me for any ignorance!

    I have a form which needs to hide certain fields based on a Dlookup result. I have an if statement on the form's on current event.

    I have tried;

    Private Sub Form_Current()
    If DLookup("RoleName", "qryRole", "RoleName") = "Dividends/Commissions" Then
    Me.[Bank Modified Date].Visible = True
    Else: Me.[Bank Modified Date].Visible = False
    End If
    End Sub

    as well as

    Private Sub Form_Current()
    If DLookup("RoleName", "qryRole", "RoleName='Dividends/Commissions'") Then
    Me.[Bank Modified Date].Visible = True
    Else: Me.[Bank Modified Date].Visible = False
    End If
    End Sub


    neither of which are hiding the field that needs to be hidden - does anyone have a suggestion? Perhaps my syntax is incorrect?

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    The first procedure is syntactically incorrect, the second procedure is syntactically correct, kind of, but makes little sense.

    You wrote:
    Code:
    If DLookup("RoleName", "qryRole", "RoleName='Dividends/Commissions'") Then
    This means "If DLookup(...) returns something that can be evaluated as True then...". I would have expected:
    Code:
    If DLookup("RoleName", "qryRole", "RoleName='Dividends/Commissions'") = <Something> Then
    Moreover, the DLookup function can return Null, which you should take into account. It can be handled with the Nz() or IsNull() function.
    Have a nice day!

  3. #3
    Join Date
    May 2004
    Location
    New York State
    Posts
    1,178
    it looks like commissions and dividends are both numeric. If that's so, lose the quotes. Instead of DLookup
    ("RoleName", "qryRole", "RoleName='Dividends/Commissions'")
    try
    Code:
    DLookup("RoleName", "qryRole", "RoleName=" & Dividends/Commissions & ")"
    Since it's unclear where the two variables are coming from, it might work if you try
    Code:
    DLookup("RoleName", "qryRole", "RoleName=Dividends/Commissions)"
    Sam

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    have you put a watch on the code and see what happens


    it could be the code itself isn't firing
    it could be that you are doing something somewhere else that overrrides this


    start with the basics


    I think you real problem is that you don't understand DLOOKUP
    my interpretation of your code is
    that you are returning the value of a column called RoleName, yet you specify that you are limiting the rowes returned where RoleName = "Dividends/Commissions"

    effectively you are asking the db is their a rolename of 'Dividends/Commissions'

    perhaps if you outline what it is you are trying to do, without referring to the code for now.

    ie what I want is:-
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •