Results 1 to 5 of 5
  1. #1
    medady is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2013
    Posts
    2

    Use DLookup to get data from multiple tables

    Hello,



    I have a big table "Table1" and a form linked to that table "Form1". "Table1" has 250 fields!!! I need to add about 20 fields more, as you know... access tables cannot include more than 255 fields. I've created a small table "Table2" and added those fields into it. I used the same primary key used in "Table1" so that linking tables is easier. I created a query "Query1" that has the primary key from "Table1" and the new fields from "Table2". Please don't get me wrong, the primary key in both tables is identical, same number of rows and same values in that field.

    I added the following code to Sub Form_Load for testing it.

    Code:
    Dim varX As Variant
    varX = DLookup("[NewField1]", "Query1", "[PrimaryKey] = " & Form_form1.PrimaryKey)
    If varX Is Not Null Then MsgBox varX
    Every time I open "Form1" I get the following error message

    Run-time error '2471':
    The expression you entered as a query parameter produced this error: 'Record1'

    "Record1" is the value of the PrimayKey of the record I'm trying to test out.

    When I debug I get the DLookup line highlighted, i.e. this line
    varX = DLookup("[NewField1]", "Query1", "[PrimaryKey] = " & Form_form1.PrimaryKey)

    Any ideas how to get dlookup working? Again, I'm just trying to get new fields added to "Form1", "Form1" is already linked to the big table "Table1" which doesn't have enough space to include the new required fields, that's why I'm using "Table2". Thank you!

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I have a big table "Table1" and a form linked to that table "Form1". "Table1" has 250 fields!!! I need to add about 20 fields more
    I would question why you have so many fields. Seldom is there ever a need for that many fields in a normalized database.
    Perhaps restructuring your table into a more normalized format will allow you to do what you need without having to create this "spillover" table.

    Can you explain why there are so many fields in the table (and what they are)? We may be able to offer you suggestions on how to restructure it.

  3. #3
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    Having a large number of fields in a table usually indicates that your table is not normalized. For more on normalization, check out this site. Could you provide a sampling of some of the field names in your table?

    Sorry for the duplication JoeM

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Sorry for the duplication JoeM
    No problem! It just further reinforces the concept!

  5. #5
    medady is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2013
    Posts
    2
    SOLVED! PrimaryKey is a text field, I should've noticed that . It just needed a quotation. Thank you for passing by!

    The code should be like this
    Code:
    Dim varX As Variant
    varX = DLookup("[NewField1]", "Query1", "[PrimaryKey] = '" & Form_form1.PrimaryKey & "'")
    If varX Is Not Null Then MsgBox varX

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

Similar Threads

  1. Replies: 5
    Last Post: 08-12-2013, 12:53 AM
  2. Replies: 1
    Last Post: 08-25-2012, 06:11 PM
  3. Replies: 3
    Last Post: 08-22-2012, 03:51 PM
  4. DLookUp Query across multiple tables
    By karldou in forum Queries
    Replies: 2
    Last Post: 12-19-2011, 02:26 PM
  5. Compare Data in Multiple Tables
    By Access_newbie in forum Queries
    Replies: 7
    Last Post: 07-26-2011, 11:35 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