Results 1 to 7 of 7
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Indiana, USA
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Assigning a value to a field

    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.

  2. #2
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Assigning a value to a field

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

    -- Mark Liquorman
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  3. #3
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    NYC,USA,Earth
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Assigning a value to a field

    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.

  4. #4
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Indiana, USA
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Assigning a value to a field

    Thanks Mark and Paul,

    There isn't a function on the control, that I can tell. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    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.

  5. #5
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    NYC,USA,Earth
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Assigning a value to a field

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

  6. #6
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Indiana, USA
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Assigning a value to a field

    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.

  7. #7
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Indiana, USA
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Assigning a value to a field

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

Posting Permissions

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