How to change the text box value at runtime for a Report

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shalskedar
    New Member
    • Sep 2009
    • 66

    How to change the text box value at runtime for a Report

    In the Report i need to change the value for a textbox at runtime.Below is my code used to change the value.But i m getting an error "Can't assign value to this object".


    Code:
    Private Sub Report_Open(Cancel As Integer)
    Dim a As String
    a = InputBox("enter the add")
    Me.Text2 = a
    End Sub
    Plz guide me as how can i change the Textbox value at runtime..
  • beacon
    Contributor
    • Aug 2007
    • 579

    #2
    You need to change the event to Detail_Format in order for it to assign to the textbox. So, change your code from:

    [code=vb]
    Private Sub Report_Open(Can cel As Integer)
    Dim a As String
    a = InputBox("enter the add")
    Me.Text2 = a
    End Sub
    [/code]

    to the following:

    [code=vb]
    Private Sub Detail_Format(C ancel As Integer, FormatCount As Integer)
    Dim a As String
    a = InputBox("enter the add")
    Me.Text2 = a
    End Sub
    [/code]

    and it should work.

    Out of curiousity, what are you using this for? Is your report unbound?

    Comment

    • shalskedar
      New Member
      • Sep 2009
      • 66

      #3
      Hello Beacon,
      I tried the above code in the Detail_Format event but its not working..
      May b I m going something wrong in the Control source property...
      Actually the Report in my DB is something like a Label which would randomly go on printing the Address...,once the specific Address is given.So i tried this out with the Input Box..

      Below is the Control source property value for the Textbox which shud print the

      data as

      For ex-South Avenue-3 08 FL 45 1st storey

      =[a] & [Plot] & " FL" & [Level] & " - " & [Location].

      Plz help me to rectify this..

      Comment

      • julietbrown
        New Member
        • Jan 2010
        • 99

        #4
        Your 'a' is something the user is going to type in, so I hope it's something really short ... not a whole address! I'm not sure I know what you are trying to do, exactly. You could have another go at explaining the exact purpose of the report.

        Anyway, what you can do is go to report properties 'other' and set the Filter property to ...

        Address = Enter_Address

        ... and the Filter On Load property to Yes

        Now when you open the report an 'automatic' input box will come up asking for the address, and the report will open just for that address.

        But why do you want to do this?

        Comment

        • beacon
          Contributor
          • Aug 2007
          • 579

          #5
          Hi Shalskedar,

          The solution I sent you works, but only if the text box is unbound. The reason it won't work for you is because your text box isn't unbound. Once you enter something into the Control Source, the text box can no longer have a value assigned to it dynamically, like in my example.

          For whatever it is that you are trying to do, since you still haven't really explained what your ultimate goal is, you will have to employ a different method...either using a form to pass your parameter to the query that the report is based on (go to http://www.fontstuff.com/access/acctut08.htm for more details) or maybe using the method that Juliet offered.

          Comment

          • beacon
            Contributor
            • Aug 2007
            • 579

            #6
            I may have replied too soon. I went back in and removed the control source that I entered in my test database that I was using to recreate your problem, then put the info into the code and it worked, sorta. The input box appears for EVERY record that will appear on your report, so if you typed "123" in the input box, you'll have to type "123" times the total number of records in your report. Not very handy....but here's the code nontheless.

            Change this...
            Code:
            Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer) 
            Dim a As String  
            a = InputBox("enter the add")  
            Me.Text2 = a  
            End Sub
            ...to this
            Code:
            Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer) 
            Dim a As String  
            a = InputBox("enter the add")  
            Me.Text2 = a  & [Plot] & " FL" & [Level] & " - " & [Location].
            End Sub
            Now, you may be able to input the value into a text box for a group header and then reference the text box using a second text box with a control source, but I haven't had time to test that out or not. Honestly, I think trying that out would be a colossal waste of time and would recommend one of the other solutions Juliet and I suggested.

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32656

              #7
              Put a parameter in the recordsource of the report :
              Code:
              SELECT [X],
                     [Y],
                     [Please Enter Address],
                     [Z]
              FROM   [YourTable]
              etc

              Comment

              Working...