Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function Running In Reverse & Only Once???

Status
Not open for further replies.

quest4

Technical User
Aug 27, 2001
735
US
I have a Function, when I check a check box, a group/line of text boxes should appear. If the check box is left unchecked, that previously mentioned group of text boxes should be invisible, four in all. Here is the function:
Function ShowHide100()
If Forms!frmqryECNMasterData100.Check140 = Yes Then
Forms!frmqryECNMasterData100.Label132.Visible = True
Forms!frmqryECNMasterData100.Combo133.Visible = True
Forms!frmqryECNMasterData100.Text135.Visible = True
Forms!frmqryECNMasterData100.Text137.Visible = True
Else
Forms!frmqryECNMasterData100.Combo133.Visible = False
Forms!frmqryECNMasterData100.Label132.Visible = False
Forms!frmqryECNMasterData100.Text135.Visible = False
Forms!frmqryECNMasterData100.Text137.Visible = False
End If
End Function
I can not see what is wrong with this function, but when I check the check box now the above boxes become invisible and nothing seems to turn them back on. It is like they are permently invisible, but in the property box it says visible=yes. In the forms property, OnCurrent, I have entered =ShowHide100()and in the checkbox's property, AfterUpDate, I entered =ShowHide100(). Go figure, anyone have an idea on this one? Thank you in advance for any help.
 
No Problem, foolio12. Hre it is.
Function ShowHide100()
Dim bolVisible As Boolean

If (Not IsNull(Forms!frmqryECNMasterData100!Check119)) Then
bolVisible = Forms!frmqryECNMasterData100!Check119

Forms!frmqryECNMasterData100!Label132.Visible = bolVisible
Forms!frmqryECNMasterData100!Combo133.Visible = bolVisible
Forms!frmqryECNMasterData100!Text135.Visible = bolVisible
Forms!frmqryECNMasterData100!Text137.Visible = bolVisible
End If
If (Not IsNull(Forms!frmqryECNMasterData100!Check140)) Then

bolVisible = Forms!frmqryECNMasterData100!Check140

Forms!frmqryECNMasterData100!Label77.Visible = bolVisible
Forms!frmqryECNMasterData100!MfgApprovedBy.Visible = bolVisible
Forms!frmqryECNMasterData100!MfgDate.Visible = bolVisible
Forms!frmqryECNMasterData100!MfgComments.Visible = bolVisible
End If
End Function

Like I said the text boxes just won't reappear when non-checked. Thank you for any assistance.
 
Thank you FancyPraitie, but that did not work good. When I unchecked one chkbox that was checked both lines became invisible instead of one line or group being invisible. Thank you again, for everything.
 
I'm assuming that this may be happening on the OnCurrent event of the form. So, let's do it a little differently. Try this:
Code:
Function ShowHide100()
    Dim bolVisible As Boolean

    If (Not IsNull(Forms!frmqryECNMasterData100!Check119)) Then
        bolVisible = Forms!frmqryECNMasterData100!Check119
    Else
        bolVisible = False
    End IF

    Forms!frmqryECNMasterData100!Label132.Visible = bolVisible
    Forms!frmqryECNMasterData100!Combo133.Visible = bolVisible
    Forms!frmqryECNMasterData100!Text135.Visible = bolVisible
    Forms!frmqryECNMasterData100!Text137.Visible = bolVisible
    
    If (Not IsNull(Forms!frmqryECNMasterData100!Check140)) Then

        bolVisible = Forms!frmqryECNMasterData100!Check140

    Else

        bolVisible = False

    End If

    Forms!frmqryECNMasterData100!Label77.Visible = bolVisible
    Forms!frmqryECNMasterData100!MfgApprovedBy.Visible = bolVisible
    Forms!frmqryECNMasterData100!MfgDate.Visible = bolVisible
    Forms!frmqryECNMasterData100!MfgComments.Visible = bolVisible
    
End Function
 
FancyPrairie, this makes no sense not believe it or not, I just exited Access completely and then I just started it back up and went into my dbase. I then went to the function and put in Doevents again and this time it worked correctly. I hope this is not temporary. One last question, will this work with reports also? So I hope and prey I can now finally say thank you fancyPrairie and everyone else for all of your terific help and assistance.
 
FancyPrairie, I don't want to muddy the waters, but I'll jump in with a couple of questions (just trying to learn):

1) Why the extra parentheses in the If..Then statement? Wouldn't...
Code:
If Not IsNull(Forms!frmqryECNMasterData100!Check119)
...do the same thing?

2) Why not just set the default state of the checkbox to True (or False) in the control's property sheet and avoid the Null value problem altogether?

I like your use of the Boolean variable, hadn't thought of that approach.

Just wondering...

Ken S.
 
Oops, the complete If..Then statement in item 1) of my previous post should be...

Code:
If Not IsNull(Forms!frmqryECNMasterData100!Check119) Then

Ken S.
 
Don't need the extra parens, it's more for readability (and habit). I agree, defaulting them to something (as I mentioned in a previous post) would make things easier. But, if the values for the check boxes are coming from a table and they're null, you still have a problem.
 
Thank you FancyPrairie and everyone else. I got it working correctly. All it took was the standard Bill Gates cure, reboot. After the reboot everything started running correctly. Thank you to everyone, learned alot from this one.
 
I apologize, I know this thread has started to get pretty long, but how would one go about doing this with an option group trying to disable (Enabled = False) instead of hiding multiple fields? I have this code already working:

Function =ShowHide100()

With Forms!frmRegistration!strField1
Select Case Forms!frmRegistration!optGroudpReg.Value
Case 1
.Enabled = False
Case 2
.Enabled = True
End Select
End With

End Function

I have put this in the AutoUpdate for the Option Group as well as the OnCurrent for the Form. This works for disabling one field, but I can't figure out how to get it working with multiple fields. I want the user to be able to see the fields, but just have them greyed out. Any suggestions would be greatly appreciated. Thanks.

Aidan
 
Thank you for the input. I have this working now, the only thing I have left, is to figure out how to make an OR statement out of two Chkboxes making one line Visible or Invisible. The idea about greying out instead of invisible is a good one, please let me knnow is you get it working. Maybe something like adding a line to each case to set the color to Grey or the color number of the grey you want. I have set condition colors in the past, but you can not same them that way, Access will not remember it. Thank you for the response, and good luck with your search, too.
 
I'll throw my $.02 in.

To update the controls every time you click the checkbox us the AfterUpdate event to callthe function. set your defaults to be exactly how you want them to be when you open the form.

When fully qualifying objects in VBA you do not need to use the bang(!) operator. They are objects and therefor can be addressed using the dot(.) operator. This will also allow you to get Intellisence reliably.

If the form being referenced is not the active form then declare a single reference to the form otherwise use the Me keyword or no local form designation at all.

The code could be as simple as:

Function ShowHide100()

'*****************
'If form is some other form
'Dim frmOther as Form
'Set frmOther = Forms!frmqryECNMasterData100
' - or -
'If form is active form you can use Me.

Dim blnVisible As Boolean
'e.g.
'With Me
' blnVisible = .Check119.Value
'....
'End With

blnVisible = Check119.Value

Label132.Visible = blnVisible
Combo133.Visible = blnVisible
Text135.Visible = blnVisible
Text137.Visible = blnVisible

blnVisible = Check140.Value
Label77.Visible = blnVisible
MfgApprovedBy.Visible = blnVisible
MfgDate.Visible = blnVisible
MfgComments.Visible = blnVisible

End Function

I hope this helps!

Jim Hope this helps!

Jim
 
Thank you, blanch. Boy, when something is working right, you find out a whole bunch of different ways of doning something. Thank you again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top