Results 1 to 4 of 4
  1. #1
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776

    DLookUP to open different forms...

    HI all,
    What in heavens name am i doing wrong with this DLookUP? I works in reverse no matter how i do it.
    If the look up has one or less files, then i want it to open frmContact, If it has more then one record, I want it


    to open frmSelectContactLocation.
    This should not be this hard....

    Code:
    Private Sub CmdContact_Click()
    
    
         If DLookup("[LocationID]", "[tblCompanyByLocation]", "[CompanyID]=" & [TxtCompanyID]) <= 1 Then
            DoCmd.OpenForm "frmContact"
        Else
         If DLookup("[LocationID]", "[tblCompanyByLocation]", "[CompanyID]=" & [TxtCompanyID]) > 1 Then
            DoCmd.OpenForm "frmSelectContactLocation"
         End If
          End If
    End Sub

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,407
    You should use DCount instead of Dlookup.

  3. #3
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Thanks Davegri,
    That worked out well.
    Dave

  4. #4
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,407
    Quote Originally Posted by d9pierce1 View Post
    Thanks Davegri,
    That worked out well.
    Dave
    Glad it worked out for you, and thanks for the star!

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

Similar Threads

  1. Replies: 18
    Last Post: 10-29-2017, 06:19 PM
  2. Replies: 4
    Last Post: 09-03-2016, 10:59 AM
  3. Replies: 3
    Last Post: 07-11-2014, 08:13 AM
  4. Replies: 3
    Last Post: 10-23-2013, 08:11 AM
  5. Replies: 2
    Last Post: 08-07-2013, 07:44 AM

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