Results 1 to 13 of 13
  1. #1
    mkb_cma is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    7

    Dlookup help needed

    I am making one form titled "Caravan List".I want the data for it's column "Desc" to be filled through using Dlookup whenever the Asset_ID matches the similar Asset_ID data of table titled "WorkingCaravanList".

    I used the below but it didn't worked

    Private Sub Description_AfterUpdate()
    Dim Desc As Variant
    Desc = DLookup("[Description_]", "WorkingCaravanList", "[Asset_ID]= '" & Table![WorkingCaravanList]![Asset_ ID] & "'")
    End Sub



    Please help.

  2. #2
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481

    The "where" part of your Dlookup is whacked.

    From your description of the problem, i expected to see
    Desc = DLookup("[Description_]", "WorkingCaravanList", "[Asset_ID]= '" & [OtherAsset_ ID] & "'")

    instead of

    Desc = DLookup("[Description_]", "WorkingCaravanList", "[Asset_ID]= '" & Table![WorkingCaravanList]![Asset_ ID] & "'")

    More info please.

  3. #3
    mkb_cma is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    7
    Thanks.

    I tried

    Private Sub Desc_AfterUpdate()
    Dim Desc As Variant
    Desc = DLookup("[Desc_]", "WorkingCaravanList", "[Asset_ID]= '" & [OtherAsset_ ID] & "'")
    End Sub

    But still there is an error message

    "The expression After Update you entered as the event property setting produced the following error:The object doesn't contain the automation object 'Asset_ID.'.

  4. #4
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481

    What we have here is a failure to

    Quote Originally Posted by mkb_cma View Post
    Thanks.

    I tried

    Private Sub Desc_AfterUpdate()
    Dim Desc As Variant
    Desc = DLookup("[Desc_]", "WorkingCaravanList", "[Asset_ID]= '" & [OtherAsset_ ID] & "'")
    [OtherAssetID] was to be replaced by the id that you needed to match.
    The error message suggests that [Asset_ID] isn't in the WorkingCaravanList?????

    However, that may be a reference to OtherAssetID????
    End Sub

    But still there is an error message

    "The expression After Update you entered as the event property setting produced the following error:The object doesn't contain the automation object 'Asset_ID.'.

    Your original post suggests to me that "OtherAssetID" may actually be Asset_ID, i.e. the field names are the same in both tables. The original post has the Lookup comparing "Assest_ID" to itself.

  5. #5
    mkb_cma is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    7
    Quote Originally Posted by hertfordkc View Post
    From your description of the problem, i expected to see
    Desc = DLookup("[Description_]", "WorkingCaravanList", "[Asset_ID]= '" & [OtherAsset_ ID] & "'")

    instead of

    Desc = DLookup("[Description_]", "WorkingCaravanList", "[Asset_ID]= '" & Table![WorkingCaravanList]![Asset_ ID] & "'")

    More info please.

    For more info, please find attached the screen shots of the "Form" and "Table".

    Regards,

  6. #6
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    First of all, when you put Dim Desc as Variant in your code, the DLookup function is assigning its return value to that variant, not a control on your form, so take that line out.

    Assuming the names of the controls on your form are Asset_ID and Desc, then your DLookup should be something like this:

    me!Desc = DLookup("[Desc_]", "WorkingCaravanList", "[Asset_ID]= '" & me!Asset_ID & "'")

    John

  7. #7
    mkb_cma is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    7
    Quote Originally Posted by John_G View Post
    First of all, when you put Dim Desc as Variant in your code, the DLookup function is assigning its return value to that variant, not a control on your form, so take that line out.

    Assuming the names of the controls on your form are Asset_ID and Desc, then your DLookup should be something like this:

    me!Desc = DLookup("[Desc_]", "WorkingCaravanList", "[Asset_ID]= '" & me!Asset_ID & "'")

    John
    Thanks for the suggestions.I tried but problem is still there.Please find attached the screen shots of the updated code and error message.

    Regards,

  8. #8
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    In your form design, what is the setting for the After Update property of the combo box containing the Asset_ID? It has to be set to [Event Procedure] in order for your code to run.

    And what is the name of that combo box control?

    John

  9. #9
    mkb_cma is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    7
    Quote Originally Posted by John_G View Post
    In your form design, what is the setting for the After Update property of the combo box containing the Asset_ID? It has to be set to [Event Procedure] in order for your code to run.

    And what is the name of that combo box control?

    John

    Hi John,
    Thanks for your help but i am still unsuccessful.Attached is the screen shot of relevent section of the properties of "Asset_ID".

    Best Regards,

  10. #10
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    OK, that's fine. Now, what is the code in that Event Procedure?

    John

  11. #11
    mkb_cma is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    7
    Quote Originally Posted by John_G View Post
    OK, that's fine. Now, what is the code in that Event Procedure?

    John
    Thanks John,

    Attached is the screen shot of the code.


    Please check.

    Regards,

  12. #12
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    The me!Desc_ = .... statement has to be in the After Update event of Asset_ID, not Desc_. Note that your control name is [Desc_] (with an underscore), not [Desc].

    What you want to do is have the code change the description ([Desc_] every time you change (i.e. update) the Asset_ID; that's why it goes in the After Update event of Asset_ID. So, your VBA should be like this:

    me![Desc_] = DLookup("[Desc_]", "WorkingCaravanlist", "Asset_ID = '" & Me![Asset_ID] & "'" )

    This should work fine, as long as the field names are correct.

    John

  13. #13
    mkb_cma is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    7
    Quote Originally Posted by John_G View Post
    Hi -

    The me!Desc_ = .... statement has to be in the After Update event of Asset_ID, not Desc_. Note that your control name is [Desc_] (with an underscore), not [Desc].

    What you want to do is have the code change the description ([Desc_] every time you change (i.e. update) the Asset_ID; that's why it goes in the After Update event of Asset_ID. So, your VBA should be like this:

    me![Desc_] = DLookup("[Desc_]", "WorkingCaravanlist", "Asset_ID = '" & Me![Asset_ID] & "'" )

    This should work fine, as long as the field names are correct.

    John
    Thanks John for your help and patience. It worked.

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

Similar Threads

  1. Help Needed
    By sdecaire in forum Access
    Replies: 2
    Last Post: 11-11-2011, 03:07 PM
  2. Help Needed
    By vkmarty in forum Access
    Replies: 1
    Last Post: 09-23-2011, 07:23 AM
  3. Help needed
    By longbo43 in forum Access
    Replies: 3
    Last Post: 09-27-2010, 10:18 AM
  4. if or syntax help needed
    By techexpressinc in forum Queries
    Replies: 16
    Last Post: 01-11-2010, 08:03 AM
  5. Help needed...
    By Pazz in forum Access
    Replies: 0
    Last Post: 11-02-2009, 06:59 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