Results 1 to 6 of 6

Dlookup giving error

  1. #1
    shylock is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Sep 2018
    Posts
    25

    Dlookup giving error

    I want to populate a list box using the criteria contained in a combo box on the same form. I'm using DLookUp to get the data from a query. The code is shown below:



    Private Sub cboServerNm_LostFocus()
    Dim ServNmQry As String

    If Not IsNull(cboServerNm) Then
    ServNmQry = DLookup("[Description]", "qryServerToService", "[Name] = " & Me.cboServerNm)
    Me.lstServices = ServNmQry
    End If
    End Sub

    it gives the following error: Run-time error '2471' The expression you entered as a query parameter produced this error: 'Adder'
    'Adder' is the name of the server in the combo box.

    How can I get the name of the service into the list box?

    Attached Thumbnails Attached Thumbnails Dlookuperror.PNG  

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    18,948
    This should help:

    DLookup Usage Samples
    Paul (wino moderator)
    MS Access MVP
    www.BaldyWeb.com

  3. #3
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    18,948
    This may be a better solution:

    BaldyWeb - Autofill
    Paul (wino moderator)
    MS Access MVP
    www.BaldyWeb.com

  4. #4
    Gicu is offline Expert
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Posts
    523
    I assume the name field is text so try ServNmQry = DLookup("[Description]", "qryServerToService", "[Name] = """ & Me.cboServerNm &"""")

    Cheers,
    Vlad

  5. #5
    shylock is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Sep 2018
    Posts
    25
    Quote Originally Posted by pbaldy View Post
    This may be a better solution:

    BaldyWeb - Autofill
    pbaldy:

    Thanks for the reply. To further explain. The combo box contains the names of all my servers. I want another combo box on the form to display the services contained on the server that is chosen in the first combo box. There usually is multiple services on each server. So far, I have succeeded in displaying only the first service through DLookUp.

    I tried your method but do not get any results. How can I reference each row returned with the wury that follows and put them in the second combo on the form?

    Query: SELECT qryServerToService.Description FROM qryServerToService WHERE [Name] = Me.cboerverNm ORDER BY [Description];

    The query does return all rows that match the criteria. "Description" is the "Service".

  6. #6
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    18,948
    That sounds more like this:

    http://www.baldyweb.com/CascadingCombo.htm
    Paul (wino moderator)
    MS Access MVP
    www.BaldyWeb.com

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

Similar Threads

  1. Iif statement giving error
    By Tazmaniac in forum Queries
    Replies: 5
    Last Post: 03-25-2018, 12:29 PM
  2. Form with VBA code giving Error
    By tgwacker in forum Access
    Replies: 1
    Last Post: 12-03-2013, 09:14 PM
  3. DCount on a Query giving #Name? error
    By Huddle in forum Access
    Replies: 9
    Last Post: 06-20-2012, 10:40 AM
  4. DLookUp function giving invalid use of null error
    By shubhamgandhi in forum Programming
    Replies: 4
    Last Post: 07-21-2011, 05:04 PM
  5. NoData() still giving me an error.
    By cowboy in forum Programming
    Replies: 3
    Last Post: 04-08-2010, 11:26 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
  •  
Tech Forums: Microsoft Office Forums