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

    Referencing Text Boxes (Access 2000)

    I am trying to refer to a set of text boxes in a report via VBA:
    Dim TxtAm as Text box
    for count = 1 to 2
    select case count
    case is 1
    set TxtAm = me.txt1AM
    case is 2
    set TxtAm = me.txt2AM
    end select
    next count

    I get the error message "You entered an exptression that has no value" - what am I doing wrong?
    I get the same message whether TxtAM is declared as an object or a text box - and the code works fine as a form (with TxtAm as an object)
    Thanks
    Allison

  2. #2
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Referencing Text Boxes (Access 2000)

    Unfortunately, reports and forms behave somewhat differently. You don't indicate what event is triggering your code, but in general you can't change a report once it has been formatted. The usual way of doing this sort of thing is to do it in the query that is the data source for the report, and setting things on the report as bound values. Hope this helps - if not post back with more details on what you are trying to accomplish.
    Wendell

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Referencing Text Boxes (Access 2000)

    Dim .. As Text Box is illegal; I assume that the space between Text and Box is a typo. If this code worked, it would set TxtAm equal to txt1AM and then (without having done anything with it) to txt2AM. Is there a specific reason you want to refer to a text box as an object instead of using its value? What do you want to accomplish?

    Side note: using Count as the name for a variable is not a good idea, since Count is a property of several objects in VBA. If you wish, you can use something like intCount.

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

    Re: Referencing Text Boxes (Access 2000)

    Count is also a SQL reserved word.
    Charlotte

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

    Re: Referencing Text Boxes (Access 2000)

    I am using the code on the on Open event. The system is an operating theatre sheduler. I have got 3 text boxes for each day of the month - AM, Pm, and evening, and a lable for the weekday name. So, what is is each of them depends on which month we are in and various other events . The sysyem picks up the Month and year from another form - user selected - but the Count variable gives the day (it actually goes from 1 - 31 (or 30, depending)).
    What I want to do is to have a universal bit of code for evey day but whether Txt1AM or Txt2AM is selected depends on Count
    Hopes that's clear - and thanks for looking at this
    Allison

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Referencing Text Boxes (Access 2000)

    You can refer to a member of the Controls collection of a form by its numeric index or by its name: Me.Controls(3) or Me.Controls("txtSomething"). If you want to refer to a control dynamically, construct the name by concatenating fixed strings and variable values:

    For intCount = 1 To 31
    Me.Controls("Txt" & intCount & "AM").Value = "free"
    Next intCount

    The exact code to use depends on what you want to do, but I'm afraid I don't understand your explanation at all.

Posting Permissions

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