Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2010

    Unanswered: List reference needed in dlookup


    I have a query that looks up a record based off of a list selection, and displays it in a new form in a textbox. The list has 13 columns showing, I have bound 14. Even as a test I made one of the columns the PK (Column 7). When I click the command it opens the new form fine, but the text box is empty. Right now all the columns are not filled, but they will be (some will need this command to work though).

    Here is the code.

    Private Sub Command21_Click()

    DoCmd.OpenForm "Form2", acNormal, , , acEdit, acWindowNormal, " "

    [Forms]![Form2]![Text2] = DLookup("[Record]", "Employee", "[EMP_ID] = Forms.Form1.List5")

    End Sub

    I thought maybe I could reference column 7 by adding a .column(6) but it gave me the following error
    "Run-time error '3805':
    Undefined function 'Forms.Form1.List5.column' in expression "

    I got this to work on a small scale, I added a PK to a 3rd bound column with only two showing then referenced it like above and it opens the new form with the text filled out.... so I'm not sure why it's not working now Any help would be awesome.

  2. #2
    Join Date
    Dec 2010
    Unless I'm misreading this (and that's very possible), I don't think the PK is required here for referencing the selected item in a list. Normally, If a list is filled from contents of a table the record ID would be contained in Column 0 (zero) if each Listed row. You need to reference the actual list column which will hold the EMP_ID. With this in mind, I would think that:

    [Forms]![Form2]![Text2].Text = DLookup("[Record]", "Employee", "[EMP_ID] = Forms.Form1.List5.Column(0)")
    would work.

    Well, perhaps something like that

Tags for this Thread

Posting Permissions

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