• DLookup Error

    • This topic has 2 replies, 2 voices, and was last updated 16 years ago.
    Author
    Topic
    #458660

    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.

    Viewing 0 reply threads
    Author
    Replies
    • #1154029

      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.)

      • #1154050

        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.)

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

    Viewing 0 reply threads
    Reply To: DLookup Error

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: