Field visible/invisible based on field before (1 Viewer)

darkmastergyz

Registered User.
Local time
Today, 00:13
Joined
May 7, 2006
Messages
85
I have 8 fields right now: field1, field2, ... I want to make it so that if, and only if field1 is > 0 then it will display field2, and so on and so forth, so that a field is only displayed if the one before it is filled. How can I do that? Do I need to make a TON of if loops, or is there a way to group them and write some vba?
 

Moniker

VBA Pro
Local time
Today, 02:13
Joined
Dec 21, 2006
Messages
1,567
That structure doesn't make sense. What if I fill in field1, field2, and field3, which will make field4 visible, and then I delete the contents of field2? Will field1, field3, and field4 still be visible?

If you have a field that must be filled in before the next field can be altered, you're going to have to rethink your structure. If all eight fields must be filled in before you allow the user to continue, then just check for that when they click "Next", "Submit", "Continue", or whatever you have them doing.

Really, though, you didn't give enough detail for what you're trying to do. It's not difficult, but you're not going about it the right way. (And, no, it's not a giant set of loops.) Give better details for a better answer.
 

Lister

Z Shift
Local time
Today, 19:13
Joined
Aug 24, 2003
Messages
305
See if this helps you on your way.

Real simple so you will have to expand it to whatever you are wanting to do with it.
So if there is no value in Text1 and it looses focus Text2 is hidden.
If a value is entered into Text1 and refresh is clicked Text2 is visable again.

Hoep you will get the idea.

See the VBA behind.

It could be done very smoothly if you have a think and put some work into how you want the events to be handled

Good luck, hope this helps ya mate. :)
 

Attachments

  • HideFields.zip
    8.1 KB · Views: 123

Lister

Z Shift
Local time
Today, 19:13
Joined
Aug 24, 2003
Messages
305
I have used the IsNull() function to handle the evernt but you could smply change this to

If me.yourfieldname > 50 Then

And so on
 

darkmastergyz

Registered User.
Local time
Today, 00:13
Joined
May 7, 2006
Messages
85
Ok. So, basically, Monkier:

Thanks a lot for telling me about how this can be bad for the user's experience. But, basically, the 8 fields aren't required. It's a possible 8, but, the user will basically fill out 1 first, then proceed to 2, then 3, 4, and so on and so forth.

So, if say 1-5 are filled, and then 1 is removed, I'd still like 1-5 be shown. Basically, the text boxes show one more box than is filled out of the 8. I want to make sure one empty one is shown all the time in the "last" field.

By the way, I checked out the hidefields. It's kind of like it, but I'd like it more dynamic, so it changes after the user types in something vs a button click. The concept is close though.
 

Rabbie

Super Moderator
Local time
Today, 08:13
Joined
Jul 10, 2007
Messages
5,906
Is your data properly normalised. I am getting warning signals. You should be able to change the field visible property from the lostfocus event of the previous field so no need for a button click.
 

darkmastergyz

Registered User.
Local time
Today, 00:13
Joined
May 7, 2006
Messages
85
But I'd need to make an onclick for each of the boxes right. No way around making 8 things, correct?
 

qdogfball

Registered User.
Local time
Today, 00:13
Joined
Jul 24, 2007
Messages
65
In one of my databases, the user is to select items.

If they select one in particular, the invisible sub field pops up to be entered.

If one of that new pop up list is entered, another pop up field shows visible.
Code:
Private Sub CorrectResolutionYesNo_AfterUpdate()
If Me.CorrectResolutionYesNo = "No" Then
    Me.ResolutionReasonList.Visible = True
Else: Me.ResolutionReasonList.Visible = False
    Me.ResolutionReasonOtherText.Visible = False
End If
End Sub

So this is in my after Update section.

But, when you get to the first invisible text or list to work on, you need code in the got focus for the next pop up.

Code:
Private Sub ResolutionReasonList_GotFocus()
    If Me.ResolutionReasonList = "Other" Then
        Me.ResolutionReasonOtherText.Visible = True
    Else: Me.ResolutionReasonOtherText.Visible = False
    End If
End Sub
So it looks like to me, you would have a lot of Ifs to get rid of them, unless you can leave them visible once they have something entered in them.

Maybe you can use a Case statement that would work and put that in each after update or got focus event?
 
Last edited:

Users who are viewing this thread

Top Bottom