Results 1 to 6 of 6
  1. #1
    Dalagrath is offline Only a Man
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2010
    Location
    Colorado
    Posts
    45

    A bit of a pickle...

    Ok, so for my training for where I work I am learning how to filter subforms using a form and on top of that, how to use Dlookup's on the subform that correlates to a related table of the table the subform is based upon. So, for example:



    Form A has Form B as Subform

    Form B needs to have data filtered on what Form A has chosen (through combobox)

    On top of this, there needs to be 2 subforms of Form B to compare the different Filters.

    ---------------------------- The above part I can get on my own

    Now here is where everything goes down hill...

    Form B is connected to tblOne but some of the data is in a relationship with tblTwo. I need Form B to take the data from tblOne and grab the data from tblTwo using a Dlookup.

    Here is the coding I have tried so far:

    Code:
    =DLookUp("[WeaponName]","tblWeapons","[WeaponID] = " & "'" & [WeaponID].[Value] & "'")
    Code:
    =DLookUp("[WeaponName]","tblWeapons","[WeaponID] = " & "'" & [WeaponID1].[Value] & "'")
    Code:
    =DLookUp("[WeaponName]","tblWeapons","[WeaponID] = " & "'" & [WeaponID1] & "'")
    ----------------------------

    I keep getting the ?#Error thing.

  2. #2
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You don't need to add ".[Value]" as the value property is the default.

    But what is the field type for [WeaponID] and [WeaponID1]?

    If it is a number (Long), then it doesn't need delimiters.

    Try:
    Code:
    =DLookUp("[WeaponName]","tblWeapons","[WeaponID] = " &  [WeaponID] )
    Code:
    =DLookUp("[WeaponName]","tblWeapons","[WeaponID] = " &  [WeaponID1] )
    Last edited by ssanfu; 05-13-2011 at 10:15 AM. Reason: spelling

  3. #3
    Dalagrath is offline Only a Man
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2010
    Location
    Colorado
    Posts
    45
    Also, the Weapon1ID is on a form, not in the table.

    Code:
    =DLookUp("[WeaponName]","tblWeapons","[WeaponID] = " & Forms![frmBattleChooser]![Weapon1ID])
    Gives me a #Name? Error.

  4. #4
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by Dalagrath View Post
    Also, the Weapon1ID is on a form, not in the table.
    Then you can't use the DLookup() function. If you look up "DLookup" in HELP:

    DLookup(expr, domain, [criteria])

    expr: An expression that identifies the field whose value you want to return.

    domain: A string expression identifying the set of records that constitutes the domain (table/ query name)

    [criteria]: An optional string expression used to restrict the range of data on which the DLookup function is performed. criteria is often equivalent to the WHERE clause in an SQL expression, without the word WHERE.

    The left part of the criteria is a field in the domain that is used to filter/select/search for the required records. If the search field is not in the domain (table), how can you search (filter) for it?

  5. #5
    Dalagrath is offline Only a Man
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2010
    Location
    Colorado
    Posts
    45
    Your saying there is no way to get a form to look up data related to the form's control source?

  6. #6
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664


    Sorry, I totally misread your post. Don't know what I was thinking.....



    Code:
    =DLookUp("[WeaponName]","tblWeapons","[WeaponID] = " & Forms![frmBattleChooser]![Weapon1ID])
    The above Dlookup() function should work..

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

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