Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2004
    Location
    austin
    Posts
    146

    Unanswered: changing .controlsource in vba

    not sure what i'm doing wrong but this is not working.

    Dim NextMonth

    NextMonth = Format(DateAdd("m", 1, Date), "MMMM YYYY")

    Me.txtDate.ControlSource = "=Enrollment Statistics: " & NextMonth

  2. #2
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    What is the error you are getting? Why are you changing the ControlSource? Why not just change the Value?

  3. #3
    Join Date
    May 2004
    Location
    New York State
    Posts
    1,178
    Quote Originally Posted by michelin man
    not sure what i'm doing wrong but this is not working.

    Dim NextMonth

    NextMonth = Format(DateAdd("m", 1, Date), "MMMM YYYY")

    Me.txtDate.ControlSource = "=Enrollment Statistics: " & NextMonth
    The txtDate.ControlSource property is always tied to the form's RecordSource property, if the form has a record source (such as a data input form). In order to change the .ControlSource, then, all you can do is change from one field in the form's RecordSource to another one, or to "unbind" it, but not to anything else. In order to access the value of a text box that is unbound, you can change the .Value in VBA, as DC suggested, without changing the .ControlSource property.

    Sam
    Last edited by Sam Landy; 02-03-05 at 13:21.

  4. #4
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    Here is another thought. Why do it in code? Why not set the ControlSource to :

    ="Enrollment Statistics: " & Format(DateAdd("m", 1, Date), "MMMM YYYY")

    Or if you have to do it in code, I just noticed that you probably have to do something like this:

    Me.txtDate.ControlSource = "='Enrollment Statistics: " & NextMonth & "'"

    If that doesn't work then try:

    Me.txtDate.ControlSource = "=""Enrollment Statistics: " & NextMonth & """"

  5. #5
    Join Date
    Jan 2004
    Location
    austin
    Posts
    146
    this worked

    Me.txtDate.ControlSource = "='Enrollment Statistics: " & NextMonth & "'"



    thanks!!!

Posting Permissions

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