By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,098 Members | 2,007 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,098 IT Pros & Developers. It's quick & easy.

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

P: 66
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".


Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Open(Cancel As Integer)
  2. Dim a As String
  3. a = InputBox("enter the add")
  4. Me.Text2 = a
  5. End Sub
Plz guide me as how can i change the Textbox value at runtime..
Feb 11 '10 #1
Share this Question
Share on Google+
6 Replies


beacon
100+
P: 579
You need to change the event to Detail_Format in order for it to assign to the textbox. So, change your code from:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Open(Cancel As Integer) 
  2. Dim a As String 
  3. a = InputBox("enter the add") 
  4. Me.Text2 = a 
  5. End Sub 
  6.  
to the following:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
  2. Dim a As String 
  3. a = InputBox("enter the add") 
  4. Me.Text2 = a 
  5. End Sub 
  6.  
and it should work.

Out of curiousity, what are you using this for? Is your report unbound?
Feb 12 '10 #2

P: 66
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..
Feb 22 '10 #3

P: 99
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?
Feb 22 '10 #4

beacon
100+
P: 579
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.
Feb 22 '10 #5

beacon
100+
P: 579
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...
Expand|Select|Wrap|Line Numbers
  1. Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer) 
  2. Dim a As String  
  3. a = InputBox("enter the add")  
  4. Me.Text2 = a  
  5. End Sub  
  6.  
...to this
Expand|Select|Wrap|Line Numbers
  1. Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer) 
  2. Dim a As String  
  3. a = InputBox("enter the add")  
  4. Me.Text2 = a  & [Plot] & " FL" & [Level] & " - " & [Location].
  5. End Sub  
  6.  
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.
Feb 22 '10 #6

NeoPa
Expert Mod 15k+
P: 31,494
Put a parameter in the recordsource of the report :
Expand|Select|Wrap|Line Numbers
  1. SELECT [X],
  2.        [Y],
  3.        [Please Enter Address],
  4.        [Z]
  5. FROM   [YourTable]
  6. etc
Feb 23 '10 #7

Post your reply

Sign in to post your reply or Sign up for a free account.