Question about VBA in the report

  • Thread starter Thread starter cdolphin88
  • Start date Start date
C

cdolphin88

Hi,

I have a report that is based on a query, but I want to use VBA code to
force something to display in the textbox, according to what is store
in the table.

For example,

If text1.text = "yes" then
text2.text ="N/A" <-- I want to force textbox2 to show me N/A
end if

but this code will work in normal VB application, not in VB inside
access....
because it give me an error

You can't reference a property or method for a control unless the
control has the focus.

So, how should I do? Can someone help me?

Cheers!

Claudi
 
Hi,

I have a report that is based on a query, but I want to use VBA code
to force something to display in the textbox, according to what is
store in the table.

For example,

If text1.text = "yes" then
text2.text ="N/A" <-- I want to force textbox2 to show me N/A
end if

but this code will work in normal VB application, not in VB inside
access....
because it give me an error

You can't reference a property or method for a control unless the
control has the focus.

So, how should I do? Can someone help me?

In Access the Text property is not the same as what it is in VB. Use the
Value property instead. Since that is the default property you don't even
need to explicitly include it...

If Me!text1 = "yes" Then
Me!text2 ="N/A"
Else
Me!text2 = ""
End If

You do need the else block above otherwise once the Me!text2 is set to "N/A"
it will stay that way for the rest of the report.
 
Hi Rick,

Now gives me another error:

You can't asign a value to this object

Cheers!

claudi
 
Is Text2 bound to an expression or a field? What is the Control Source of
Text2?

--
Duane Hookom
MS Access MVP

Hi Rick,

Now gives me another error:

You can't asign a value to this object

Cheers!

claudi
 
Duane said:
Is Text2 bound to an expression or a field? What is the Control Source of
Text2?

The control source Is a query. Text2 bound to a field of a table


Claudi
 
A "Control Source" can't be a query. A Record Source of a report can be a
query. If this was a form, you should be able to place a value in the bound
control. Since this is a report, you can't insert a value into a bound text
box.

What are you attempting to accomplish? Can't you set the control source of
the text box to something like:

=IIf([Text1]="Yes","N/A",Null)
 
If you get this a second time, my apologies. Got a network error.
I would make the bound control not visible and use an unbound control to
display the result of the code. I would put the code in the Format event of
the section the control is in.

I have not tested this. I was just my first thought.
 
Back
Top