Results 1 to 8 of 8
  1. #1
    mkallover is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    25

    Help with IF statement

    For some reason I just can't get this to work. On load I have a sub that checks the current project number against a table. Depending on whether or not the project number is on the table one of several different labels is displayed at the bottom of the form.

    However, if the user has no active projects, the line with the Dlookup is throwing a "You entered an expression that has no value." VB error back at me.

    Code:


    Code:
    If IsNull(Forms!frmMain!frmMainMyProj!CPOProjectNum) Then
    Exit Sub
    Else
    
    If IsNull(DLookup("CPOProjectNum", "qryMyProj", "CPOProjectNum = '" & Forms!frmMain!frmMainInfo!CPOProjectNum & "'")) Then
    Me.Follow.Visible = True
    Me.Following.Visible = False
    Me.NoFollow.Visible = False
    Else
    Me.Follow.Visible = False
    Me.Following.Visible = True
    Me.NoFollow.Visible = True
    End If
    
    End If

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I suspect you're running into this issue:

    http://www.mvps.org/access/forms/frm0022.htm

    Given what you appear to be doing, you could also try a DCount() instead of DLookup() and test for 0.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    mkallover is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    25
    I tried:

    Code:
    Dim CheckCount As Long
    
    CheckCount = DCount("CPOProjectNum", "qryMyProj", "CPOProjectNum = '" & Forms!frmMain!frmMainInfo!CPOProjectNum & "'")
    
    If CheckCount = 0 Then
    Exit Sub
    Else
    
    If IsNull(DLookup("CPOProjectNum", "qryMyProj", "CPOProjectNum = '" & Forms!frmMain!frmMainInfo!CPOProjectNum & "'")) Then
    Me.Follow.Visible = True
    Me.Following.Visible = False
    Me.NoFollow.Visible = False
    Else
    Me.Follow.Visible = False
    Me.Following.Visible = True
    Me.NoFollow.Visible = True
    End If
    
    End If
    That gives me an error of "You entered an expression that has no value"

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    If the problem is that the subform has no records, I'd use that link, or a technique like it. Or is there a Null value there? Can you post the db?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    mkallover is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    25
    I can't post the Db because it contains proprietary info but the problem occurs when the subform has no records. I'll try that link but I'm having trouble grasping how I'd use it.

    To use that method would I just do:

    If nnz(Forms!frmMain!frmSub!FieldName) = 0 Then
    Do.Stuff
    Else
    Do.OtherStuff
    End If

    Where Stuff is what I want it to do if there are no records in the subform and OtherStuff is what I want it to do if there are records in the subform?

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    That looks about right; it should return 0 when the subform has no records.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    mkallover is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    25
    Awesome, thank you. I'll give that a try ASAP.

    Edit: Worked great! Thanks again!

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help; glad we got it sorted out.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Need Help with SQL Statement
    By Hank44 in forum Programming
    Replies: 3
    Last Post: 11-08-2010, 05:49 PM
  2. Help with Iif statement
    By tmcrouse in forum Queries
    Replies: 2
    Last Post: 09-02-2010, 09:00 AM
  3. IIf Statement
    By dref in forum Forms
    Replies: 2
    Last Post: 07-16-2010, 02:46 AM
  4. IIF statement
    By james1982 in forum Access
    Replies: 1
    Last Post: 07-20-2009, 09:38 AM
  5. how to use IF then statement
    By ronnie4 in forum Access
    Replies: 1
    Last Post: 03-17-2009, 11:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums