Results 1 to 9 of 9
  1. #1
    2 Star Lounger
    Join Date
    Oct 2001
    Location
    Suffolk, England
    Posts
    134
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Assign value to a Text Box (Access 2000)

    When I try and assign a value to a text box - (Me.textbox.value = 0 - or even Me!textbox.value = 0 ) for instance I get the error - 'You can't assign a value to this object'. However if I reference the text box from a parent form - Me.Parent!ParentForm!textbox.value = 0, it works. I realise I am probably doing something stupid - but that's how it goes!

    Allison

  2. #2
    3 Star Lounger
    Join Date
    Mar 2001
    Location
    Frederick, Maryland, USA
    Posts
    296
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Assign value to a Text Box (Access 2000)

    Try this...Right click the text box, select Properties, select the Data tab, and place your desired value in the Default Value field.

  3. #3
    2 Star Lounger
    Join Date
    Oct 2001
    Location
    Suffolk, England
    Posts
    134
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Assign value to a Text Box (Access 2000)

    I want to assign a value which will change depending on the month I am reporting on - so a default value won't work!

  4. #4
    3 Star Lounger
    Join Date
    Mar 2001
    Location
    Frederick, Maryland, USA
    Posts
    296
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Assign value to a Text Box (Access 2000)

    I think you'll have to do this in code, using the After Update event of the Month field. That way, after you update the Month field by selecting a particular month, you could populate your Text box by using a series of If/Then statements. Here's some sample code I've used to do essentially the same thing. As you can see, depending upon the value of Me!CLIN, certain events occur in other fields on my form:

    Private Sub CLIN_AfterUpdate()
    If Me!CLIN = "0001" Then
    Me!FundStatus = "FUNDED"
    Me!FundStatus.Enabled = False
    Me!FundPrimeModNo = "CLIN0001"
    Me!FundPrimeModNo.Enabled = False
    Me!SLIN.Enabled = False
    ElseIf Me!CLIN = "0008" Or Me!CLIN = "0063" Then
    Me!SLIN.Enabled = True
    Else
    Me!FundStatus.Enabled = True
    Me!FundPrimeModNo.Enabled = True
    Me!SLIN.Enabled = False
    End If
    End Sub

    Good luck!

  5. #5
    2 Star Lounger
    Join Date
    Oct 2001
    Location
    Suffolk, England
    Posts
    134
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Assign value to a Text Box (Access 2000)

    Thanks for trying, but it still isn't working. If I put Me!textbox = 0 it still says 'You can't assign a value to this object" It works in Access 97.
    Allison

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Assign value to a Text Box (Access 2000)

    Do you actually have a control called textbox on the current form? Is its control souce a formula? In that case, you can't assign a value to it. I suspect you're using generic examples. Why don't you post the specific code that's giving you the error.
    Charlotte

  7. #7
    2 Star Lounger
    Join Date
    Oct 2001
    Location
    Suffolk, England
    Posts
    134
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Assign value to a Text Box (Access 2000)

    This is the bit that's causing the problem. The Select for February works, but doesn't for March - whether the statements are Me.TxtTotalAdd.Value = 0 or as written.

    Case Is = "February"
    Me.TxtTotalAdd.ControlSource = "[MarchAdd]"
    Me.TotalSpend.ControlSource = "=Sum([MarchAdd])"

    Case Is = "March"
    Me!TxtTotalAdd = 0
    Me!TotalSpend = 0
    End Select

  8. #8
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Assign value to a Text Box (Access 2000)

    In February you change the control source. If [MarchAdd] is also a calculated field like "=Sum([MarchAdd])", then the two textboxes are calculated and cant be changed. You can change the control source.
    Change to
    Case Is = "March"
    Me!TxtTotalAdd.ControlSource = "=0"
    Me!TotalSpend.ControlSource = "=0"
    Francois

  9. #9
    2 Star Lounger
    Join Date
    Oct 2001
    Location
    Suffolk, England
    Posts
    134
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Assign value to a Text Box (Access 2000)

    Thanks - that's done it

    Allison

Posting Permissions

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