Results 1 to 3 of 3

Thread: DLookup Error

  1. #1
    4 Star Lounger
    Join Date
    Feb 2006
    Posts
    504
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    I have the following DLookUp codes in one of form:

    varName = DLookup("[Name]", "table", "[Invoice#] = " & Me.[Invoice#])
    If Not IsNull(varName) Then
    Me.Name = varName
    End If

    varDate = DLookup("[Date]", "table", "[Invoice#] = " & Me.[Invoice#])
    If Not IsNull(varDate) Then
    Me.Date = varDate
    End If

    But I don't know if I add the varName codes, I will get this error message:Run-time error '2135': THis property is read-only and can't be set.

    However, if I only have varDate and then the codes works well.

    Any idea?

    Thanks in advance.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Me.Name refers to the built-in Name property of a form - it's the name that you see in the database window. You can't change this property while the form is open in form view.

    For that reason, it's not a good idea to give a field or control the name "Name". It causes confusion. But if you won't or can't change it, you must put the word Name between square brackets if you want to refer to a control named "Name" instead of to the name of the form:

    Me.[Name] = varName

    (I wouldn't call a field or control Date either, since Date is a built-in VBA data type.)

  3. #3
    4 Star Lounger
    Join Date
    Feb 2006
    Posts
    504
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='768065' date='28-Mar-2009 23:57']Me.Name refers to the built-in Name property of a form - it's the name that you see in the database window. You can't change this property while the form is open in form view.

    For that reason, it's not a good idea to give a field or control the name "Name". It causes confusion. But if you won't or can't change it, you must put the word Name between square brackets if you want to refer to a control named "Name" instead of to the name of the form:

    Me.[Name] = varName

    (I wouldn't call a field or control Date either, since Date is a built-in VBA data type.)[/quote]

    Thanks, Hans. It works after I rename the control of the name "Name".

Posting Permissions

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