Results 1 to 8 of 8
  1. #1
    2 Star Lounger
    Join Date
    Apr 2003
    Location
    Vail, Colorado, USA
    Posts
    194
    Thanks
    36
    Thanked 0 Times in 0 Posts

    Acess Controls programatically (2000)

    I am populating a report with controls usings series of procedures controlled by start and finish dates entered on a from. My problem is I cannot work out how to a) setthe name of the textbox controls I set and also I cannot access them. What I want to do is set some fields to different widths but everything I have tried will not allow me to get to the names assigned to the controls whenthey were created. I have a dimenisoned array "ctlText" that I use to set a series of weeks. Automayically they are assigned Text0 and up. When I try and name the control using Reports(rptname).controls."text" & n.name = "X " I am told I cannot use this in design view. Rptname is a variable the program generates when savingthe report, "n" is the number in a for next loop. Can anyone help thank you.

    Peter

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

    Re: Acess Controls programatically (2000)

    Code like this should work if the report "rptMyReport" is open in design view - it worked for me in Access 97 and Access 2002 (I don't have Access 2000, but it seems improbable that code that worked in other versions wouldn't work there):

    Dim ctl As Control
    ' Create control
    Set ctl = CreateReportControl( _
    ReportName:="rptMyReport", _
    ControlType:=acTextBox, _
    Left:=100, _
    Top:=100, _
    Width:=1440, _
    Height:=240)
    ' Name control
    ctl.Name = "txtMyTextBox"
    Set ctl = Nothing

    The values assigned can be expressions instead of constants.

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

    Re: Acess Controls programatically (2000)

    >>Reports(rptname).controls."text" <<

    Your problem is the syntax you are using to specify a control. The above syntax works only when you specifically know the control name, you can't use it when you want to use a variable or to construct a name. For example, use this instead (I'm using the variables rptname and controlname):
    Reports(rptname)(controlname)
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  4. #4
    2 Star Lounger
    Join Date
    Apr 2003
    Location
    Vail, Colorado, USA
    Posts
    194
    Thanks
    36
    Thanked 0 Times in 0 Posts

    Re: Acess Controls programatically (2000)

    Your suggestion worked fine for setting the control itself but not for the name. the code I wrote is.
    Sub weeks()
    Dim ctl As Control
    xy = 3000
    For n = Fweek To LWeek
    Set ctl = CreateReportControl( _
    reportname:=rptName, _
    ControlType:=acTextBox, _
    Left:=xy, _
    Top:=0, _
    Width:=1440, _
    Height:=240)
    ctl.Name = "week" & n
    xy = xy + 1500
    Set ctl = Nothing
    Next
    End Sub

    The procedure is called from another and I put a breakpoint in to make sure that I could see it and as I said it executed the creation part of the loop but not the name. Any other suggestions gratefully appreciated. I tried the name without the concatenation and that did not help. The error by the way was "run time 2455" and the message "Invalid reference to property name"
    Thanks again.

    Peter

  5. #5
    2 Star Lounger
    Join Date
    Apr 2003
    Location
    Vail, Colorado, USA
    Posts
    194
    Thanks
    36
    Thanked 0 Times in 0 Posts

    Re: Acess Controls programatically (2000)

    Unfortunately I do not know what holds the variable name for the control. I have dimensioned a dynamic array ctlText(52) and then used CreatReportControl to create the control. I have tied using msgbox to see if it will return a vale for ctlText() without success. I know the names actually used by looking at the form after creation and I see they are Text plus an incrementing number. The relevant part of the code follows.

    Dim ctltext(52) As Control, ctltext2 As Control, ctllabel(52) As Control, ctllabel2 As Control
    Reports(rptName).Section(acPageHeader).Height = 500 'sets height of header
    Reports(rptName).Section(acDetail).Height = 250 'sets the height of the detail section.
    Set ctltext2 = CreateReportControl(rptName, acTextBox, acDetail, , _
    "fullname", 0, 0, 980, 200)
    Set ctllabel2 = CreateReportControl(rptName, acLabel, acPageHeader, , _
    "Name", 0, 250, 980, 200)
    Set ctltext2 = CreateReportControl(rptName, acTextBox, acDetail, , _
    "pledgeamount", 1000, 0, 980, 200)
    Set ctllabel2 = CreateReportControl(rptName, acLabel, acPageHeader, , _
    "Amount", 1000, 250, 980, 200)
    Set ctltext2 = CreateReportControl(rptName, acTextBox, acDetail, , _
    "envelopenumber", 2000, 0, 980, 200)
    Set ctllabel2 = CreateReportControl(rptName, acLabel, acPageHeader, , _
    "Env #", 2000, 250, 980, 200)
    xy = 3000
    ' weeks
    For n = Fweek To LWeek
    Set ctltext(n) = CreateReportControl(rptName, acTextBox, acDetail, , _
    "week" & n, xy, 0, 1440, 200)
    'Set ctltext(n).Name = "week" & n
    xy = xy + 800
    Next n


    I would be very gratefull for any further help.

    thanks

    Peter

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

    Re: Acess Controls programatically (2000)

    I fear that you're trying to do too much at once and that something else is interfering. I copied your Weeks procedure into a module and added the missing declarations. It worked without a hitch - it added the text boxes and assigned the names as intended! (BTW I hope that you have Option Explicit in all your modules)

    I suggest that you start by practicing this in a new database with just one report and one code module until you get it right, then try the same code in (a copy of) your "real" database, and then add the bells and whistles one by one.

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

    Re: Acess Controls programatically (2000)

    >>Set ctltext2 = CreateReportControl(rptName, acTextBox, acDetail, , _
    "fullname", 0, 0, 980, 200)<<

    You say to don't know what holds the variable name for the control? Well, you know the control, so it is easy to get the name. The syntax to address the control you created above is:
    Reports(rptName)(ctlText2.name)
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  8. #8
    2 Star Lounger
    Join Date
    Apr 2003
    Location
    Vail, Colorado, USA
    Posts
    194
    Thanks
    36
    Thanked 0 Times in 0 Posts

    Re: Acess Controls programatically (2000)

    Thanks Hans

    I did not have option explict set. I tried that first in my real database, and after tidying up the variables I tried agian same result. So I took your advice and so far it is working. But the building process is time comsuming.

    Anyway it works so thanks for that.

    Regards

    Peter

Posting Permissions

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