More End Sub?

A

an

Hello!

I have [Event Procedure] On Current in Form.
There, I need to whrite some rows with code to hide
fields, by some conditions.

Example:

Private Sub Form_Current()

If [A] = "A" Then
[Field1].Visible = False
Else
[Field1].Visible = True
End If


If = "B" Then
[Field2].Visible = False
Else
[Field2].Visible = True
End If


If [C] = "C" Then
[Field3].Visible = False
Else
[Field3].Visible = True
End If

EndSub


But only acept the last conditon, before End Sub.
How is possible to repeat this procedures to acept all
conditions, please?

Thanks in advance.
an
 
D

Dirk Goldgar

an said:
Hello!

I have [Event Procedure] On Current in Form.
There, I need to whrite some rows with code to hide
fields, by some conditions.

Example:

Private Sub Form_Current()

If [A] = "A" Then
[Field1].Visible = False
Else
[Field1].Visible = True
End If


If = "B" Then
[Field2].Visible = False
Else
[Field2].Visible = True
End If


If [C] = "C" Then
[Field3].Visible = False
Else
[Field3].Visible = True
End If

EndSub


But only acept the last conditon, before End Sub.
How is possible to repeat this procedures to acept all
conditions, please?

Thanks in advance.
an


I'm afraid I don't understand you. There's nothing obviously wrong with
the code you posted, except that you can't hide a control that has the
focus, so if [Field1] currently has the focus you can't say
"[Field1].Visible = False" without first setting the focus someplace
else.
 
A

an

Thanks for your replay and remark.
I think so, but I haven't solution for this.
Can you help me?
Any solution is welcome.
an
-----Original Message-----
Hello!

I have [Event Procedure] On Current in Form.
There, I need to whrite some rows with code to hide
fields, by some conditions.

Example:

Private Sub Form_Current()

If [A] = "A" Then
[Field1].Visible = False
Else
[Field1].Visible = True
End If


If = "B" Then
[Field2].Visible = False
Else
[Field2].Visible = True
End If


If [C] = "C" Then
[Field3].Visible = False
Else
[Field3].Visible = True
End If

EndSub


But only acept the last conditon, before End Sub.
How is possible to repeat this procedures to acept all
conditions, please?

Thanks in advance.
an


I'm afraid I don't understand you. There's nothing obviously wrong with
the code you posted, except that you can't hide a control that has the
focus, so if [Field1] currently has the focus you can't say
"[Field1].Visible = False" without first setting the focus someplace
else.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


.
 
J

John Vinson

Please post your *actual* code. As written, this should execute all
the IF's and toggle the visibility of all the controls independently.
What is in fact happening?
 
A

an

Thanks for your remark.
The situation is:

Only execute the procedure If in 3ª position correctly:
If [C] = "C" Then
....
....
End Sub

The 1st and 2nd If's don't work, but, if I change the 1st
or 2nd If to 3rd position, it work fine also. Only that
position.

I don't know why... (Ignorance!)

Thanks.
an
 
R

Rod Scoullar

You could try

Field1.Visible = Not ([A] = "A")
Field2.Visible = Not ( = "B")
Field3.Visible = Not ([C] = "C")

or alternatively

Field1.Visible = ([A] <> "A")
etc.

but as others have said your original code should work as you have shown it.

Someone suggested that you post the actual code. This would be a great
help.
 
D

Dirk Goldgar

an said:
Thanks for your replay and remark.
I think so, but I haven't solution for this.
Can you help me?
Any solution is welcome.

I don't understand your reply. If the problem is that the control
you're trying to hide currently has the focus, you can set the focus
somewhere else. Since it isn't clear at the beginning of the event
procedure which of the controls listed in the procedure will be visible
at the end of it, pick some control that is not currently involved, that
will always be enabled and visible, and set the focus there at the
start.

For example, suppose that you have a control named "txtHeader" that will
always be visible, not hidden by the code. Then you would put the line

Me!txtHeader.SetFocus

at the start of the event procedure, before going through the code and
possibly hiding some of the other controls.

If this isn't the problem you are having, you must post your actual code
so that people can see what may be going wrong.
 

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