Results 1 to 6 of 6
  1. #1
    shylock is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Sep 2018
    Location
    Dayton, Ohio
    Posts
    100

    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 offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    This should help:

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

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

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

  4. #4
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    I assume the name field is text so try ServNmQry = DLookup("[Description]", "qryServerToService", "[Name] = """ & Me.cboServerNm &"""")

    Cheers,
    Vlad

  5. #5
    shylock is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Sep 2018
    Location
    Dayton, Ohio
    Posts
    100
    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 offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    That sounds more like this:

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