• Assigning a value to a field

    Author
    Topic
    #356729

    Access 97, Windows 95

    Can a value be assigned to a field using VBA code?

    Here is what I am trying to do:

    Dim strEmail As String

    strEmail = Left(strPICFirstName, 1) & “” & Left(strPICLastName, 7) & “” & “@dem.state.in.us”
    Me!strEmailAddress = strEmail

    Stepping through the code, “strEmail” results in the correct string, but “Me!strEmailAddress = strEmail” gives a Run-time error ‘2448’: You can’t assign a value to this object.

    Thanks.

    Viewing 1 reply thread
    Author
    Replies
    • #528506

      I’m guessing you have a controlsource for that control which contains a function. This essentially makes that control “read-only”.

      — Mark Liquorman

    • #528514

      In which event are you trying to write the value to the control? Is this on a form? More detailed info is needed to successfully answer your question.

      • #528518

        Thanks Mark and Paul,

        There isn’t a function on the control, that I can tell. smile

        The control is on a form. What I am trying to do is to have the email address for our staff to be written to a field on a form which would then be added to the control source table. We have a standard email address system (probably like most places). Instead of having to write each one, this code, when it works, will do it automatically.

        HTH you two and me.

        • #528535

          When do you want to assign the value to the control? Where is the data comming from?

          • #528620

            I have the code in the On Open event. The two name fields are on the form as well as the email field. It may be that the On Open event is not the place for the code. I will try it another way. Still, if you guys have any suggestions, please send them and thanks.

            • #528625

              Problem solved. I placed the code on the Got Focus event of the strPICLastName control and it worked. Thanks again.

    Viewing 1 reply thread
    Reply To: Assigning a value to a field

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

    Your information: