Visible based on conditions met

T

Tim

I don't know why my following codes don't work. Can you help me? I already
created a textbox (txt1) in the Detail section.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me!txt1.Value = "ABC" Then
txtPara1ABC.Visible = -1
txtPara1SomethingElse.Visible = 0
Else
txtPara1SomethingElse.Visible = -1
txtPara1ABC.Visible = 0
End If
End Sub
 
F

fredg

I don't know why my following codes don't work. Can you help me? I already
created a textbox (txt1) in the Detail section.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me!txt1.Value = "ABC" Then
txtPara1ABC.Visible = -1
txtPara1SomethingElse.Visible = 0
Else
txtPara1SomethingElse.Visible = -1
txtPara1ABC.Visible = 0
End If
End Sub

Words like "Codes don't work" do not really help us very much.
What doesn't work?
You get an #error in the control?
Your code stops running because of an error?
No changes occur?
Did you place a breakpoint in the code and step through it to see what
is happening?
What?

Anyway, what is [txt1]?
Is it bound to a field in the report's record source?
Or is it an unbound control (most likely from it's name)?

If it is a bound control, then you can simplify your code to this:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
txtPara1ABC.Visible = Me!txt1 = "ABC"
txtPara1SomethingElse.Visible =Not Me!txt1= "ABC"
End Sub

But first you have to make sure that there is a value in [txt1].
 
E

Evi

if you write it this way, does it still not work? It's fairly standard code
so it ought to be OK if this is all there is in it.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.txt1 = "ABC" Then
Me.txtPara1ABC.Visible = True
Me.txtPara1SomethingElse.Visible = False
Else
Me.txtPara1SomethingElse.Visible =True
Me.txtPara1ABC.Visible = False
End If
End Sub

Just make sure that you've got the name of your controls right.
Is this a quote from a larger piece of code, by any chance?
Do you get any errors when you Debug?
 
T

Tim

Hi Evi:
I really don't know why they are not working. When I open the report, since
the txt1 <> "ABC", the txtPara1SomethingElse is supposed to be showed up.
However, both txtPara1ABC and txtPara1SomethingElse don't show up!

In the Visible properties of these paragraphs, I set "No". These are just
the same codes; I just change the names. Do you think these codes just work
for earlier version of Access, but not Access 2003?
 
E

Evi

By 'the visible properties of these paragraphs'? Do you mean, the visible
properties of the controls (ie the text boxes)?

When I do this sort of thing, I normally set the Visible Property of a
control to Yes in the Properties box and allow the code to control if it
appears or not. Try that (although I can't see why it should make a
difference).

I don't know if Access 2003 has found some other way of dealing with
visible - I have Acc2000 - but I've never seen anything to suggest this so
I'm guessing not.

Remove your code temporarily and just check that txt1 DOES sometimes say
ABC.

Check your code that you haven't got your True and Falses mixed up - I'm
guessing that you are just posting a paraphrase of it and you may find that
your actual code doesn't read the same way. It may help if you copy and
paste the real code. It may have other parts in it which cause your
Visible/not visible section to be bypassed.

In particular, take any error handlers out of your real code and especially
any On Error Resume Next's (you can imagine what havoc that could wreak on a
typo) and run a Debug.
That should highlight faults like missing References
If your real code refers to any functions (in a module perhaps) that could
be the cause of the problem.

Evi
 
T

Tim

Evi,
Thanks a lot for trying helping me! You gave various situations to check my
codes. I appreciate that.
Acctually, I made a copy of the database re-do the report again and you know
what, the problem is that I put the wrong the control name. Instead of using
the control name like Me!controlname, I used Me!fieldname (incorrect). I
think there is something to do with the bang notation (!) or dot notation(.),
i.e., I should write
Me!txt1 instead of Me.txt1

tim
 
E

Evi

No, writing Me.txt1 works fine because as soon as you write the box, a drop
down list appears will all the possible options available. It can save a few
typos.
Glad you found the error, they can be little beggars to hunt down.

Evi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top