Modify text box display in detail based on a value

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a text box in the detail called txtAccountNo. It populates from a
variable called AccountNo and it is usually 13 characters long. However, if
the record being read has AccountType = "WC" or "CO", then I want
txtAccountNo to display only the first 6 characters of the AccountNo. I tried
to manipulate .ControlSource as a property or method of Me!txtAccountNo but
got nowhere. Can anyone help me with this please?
 
Excuse me, the AccountType is actually read from a form. So I should have
said: if myfrm!AccountType = "WC" or myfrm!AccountType = "CO" then I want to
modify what gets displayed in txtAccountNo.
 
I resolved this by creating two text boxes, txtAccountNo and txtInvoiceNo and
placing one on top of the other. Then I added the code:

Me!txtInvoiceNo.Visible = (AccountType = "WC" or AccountType = "CO")
Me!txtAccountNo.Visible = Not Me!txtInvoiceNo.Visible

That got me the result I want, unless someone has a more elegant way to do it.
 
richardb said:
I resolved this by creating two text boxes, txtAccountNo and txtInvoiceNo and
placing one on top of the other. Then I added the code:

Me!txtInvoiceNo.Visible = (AccountType = "WC" or AccountType = "CO")
Me!txtAccountNo.Visible = Not Me!txtInvoiceNo.Visible

That got me the result I want, unless someone has a more elegant way to do it.


I would have done it with one txtAccountNo text box using a
control source expression:

=IIf(myfrm!AccountType IN("WC", "CO"), Left(AccountNo,6),
AccountNo)
 
Hi Marshall,

That was really helpful. Can we try another variation? This report has a lot
of code behind it. The report really retrieves the data from one source or
another depending on whether I'm printing the original report or a stored
copy of a previously generated report. Consequently, I get the value of
"Account Type" from either a form or a table and the first thing I do is to
store it in a variable called strAccountType that is declared in the report
code itself. Now the format of my text box depends on the value of
strAccountTyppe. How would you change my txtInvoiceNo from AccountNo to
Left(AccountNo, 6) if strAccountType = "WC" or "CO"?
 
richardb said:
That was really helpful. Can we try another variation? This report has a lot
of code behind it. The report really retrieves the data from one source or
another depending on whether I'm printing the original report or a stored
copy of a previously generated report. Consequently, I get the value of
"Account Type" from either a form or a table and the first thing I do is to
store it in a variable called strAccountType that is declared in the report
code itself. Now the format of my text box depends on the value of
strAccountTyppe. How would you change my txtInvoiceNo from AccountNo to
Left(AccountNo, 6) if strAccountType = "WC" or "CO"?


Either use an invisible text box instead of the variable, or
use code set the value of the invoice text box:

Select Case strAccountType
Case "WC", "CO"
Me.txtInvoiceNo = Left(Me.AccountNo, 6)
Case Else
Me.txtInvoiceNo = Me.AccountNo
End Select

I must add that I am uncomfortable using hardcoded values
such as "WC" and "CO". Wouldn't it be more general if you
had a table of Account Types and another field that
specified if the display is truncated or not?
 
That will do it. Actually, the Account Type is already displayed in the
heading of the report, so I can use your select case from that. By the way
"WC" and "CO" are not hard coded. They are selected from the table of Account
Types in the medical billing database and used to limit the original open
item collections report; then stored as a reference for future reprinting of
the same report.

Many thanks...I learned something.
 
Back
Top