Hiding Text box code

CEH

Curtis
Local time
Today, 17:13
Joined
Oct 22, 2004
Messages
1,187
Visible problem........

I'm new to VBA..... But I can't seem to get this to work using a macro.... I have a form...to print/preview reports 3 criteria- 3 radio buttons.. "By Date" "By #" and "By Job#" .... beside each button are two boxes for "From" and "To"..... I'm sure this is a common form,I see it alot....... I am having trouble with the "visible" on the "From" and "To" boxes........ All are set to "NO" on the unbound box property..I want no boxes to appear until a criteria is picked. So......... What I want is when you click "By Date" for the two "From" and "To" boxes for "By Date" to become visible.
I am thinking it should be something like an If...Then

If ByDate.value = 1 then
beginningDate.visible = true
EndingDate.visible = True

Any help???????

Thanks
 
I'm guessing you are using a frame.

Code:
If Me.ByDate = 1 Then
    BeginningDate.Visible = True
    EndingDate.Visible = True
Else
    BeginningDate.Visible = False
    EndingDate.Visible = False  
[b]End If[/b]
 
Nope........

The By Date....By#...and By Job# are an option group..... Option2, option4 and option6...... and the option group is called "PickReport"

What you are showing me is about what I was trying...... No it doesnt work :(

If someone would like to take a look...... Probably a little easier then me trying to explain it...... Done in Access 2002

ReportsDialog is the form
Too big to attach zip here..... So I put it on a link on this page...... only link there :)
http://www.webtekstudios.com/DatabaseLink.htm
 
Last edited:
Try Calling the following module in the after update event of PickReport, BeginningDate, etc....


Call ShowMyButtons(Me,Me!PickReport)


Sub ShowMyButtons(f As Form, PickReport As Integer)

Dim v As Boolean

With Me
Select Case (PickReport)
Case (1)
v = Not (IsNull(!BeginningDate) Or IsNull(!EddingDate))
Case (2)
v = Not (IsNull(!FromInspection#) Or IsNull(!ToInspection#))
Case (3)
v = Not (IsNull(!BeginningJob#) Or IsNull(!EndingJob#))
Case Else
v = False
End Select
!cmdPreview.Visible = v
!cmdPrint.Visible = v
!cmdPrint.Visible = v
End With

End Sub
 
Hiding Text box code.....

I finally got a form to work for making some text box visible and not visible...... Well almost......... but a few problems... I dont know why..... First here is the vba
This is probably a LONG way to do this.......... But I'm very new to VBA


Private Sub Form_Load()
BeginningDate.Visible = False
EndingDate.Visible = False
FromInspection_.Visible = False
ToInspection_.Visible = False
FromJob_.Visible = False
ToJob_.Visible = False
End Sub

Private Sub Option2_GotFocus()
BeginningDate.Visible = True
EndingDate.Visible = True
FromInspection_.Visible = False
ToInspection_.Visible = False
FromJob_.Visible = False
ToJob_.Visible = False

End Sub

Private Sub Option4_GotFocus()
BeginningDate.Visible = False
EndingDate.Visible = False
FromInspection_.Visible = True
ToInspection_.Visible = True
FromJob_.Visible = False
ToJob_.Visible = False
End Sub

Private Sub Option6_GotFocus()
BeginningDate.Visible = False
EndingDate.Visible = False
FromInspection_.Visible = False
ToInspection_.Visible = False
BeginningJob_.Visible = True
EndingJob_.Visible = True
End Sub

Private Sub Option6_LostFocus()
BeginningJob_.Visible = False
EndingJob_.Visible = False
End Sub
------------------\
Problems are............ Had to add the "LostFocus" on Option6... it would not go off...
Another problem..... When you open the form... The first pick "option2" doesnt work the FIRST time you click it... but if you click another option...both work... then come back to "Option2" it works....???????????????????????
Finally........ my date input is set to "Short Date".... If I change it... like Ive done in other forms to 6 places "00/00/00" it gives me back an error....

Any thoughts???
Thanks
 
CEH said:
Private Sub Form_Load()
BeginningDate.Visible = False
EndingDate.Visible = False
FromInspection_.Visible = False
ToInspection_.Visible = False
FromJob_.Visible = False
ToJob_.Visible = False
End Sub

You can set the Visible property of these controls to False and save the form. Therefore there will be no need for this.

Private Sub Option2_GotFocus()
BeginningDate.Visible = True
EndingDate.Visible = True
FromInspection_.Visible = False
ToInspection_.Visible = False
FromJob_.Visible = False
ToJob_.Visible = False

End Sub

Private Sub Option4_GotFocus()
BeginningDate.Visible = False
EndingDate.Visible = False
FromInspection_.Visible = True
ToInspection_.Visible = True
FromJob_.Visible = False
ToJob_.Visible = False
End Sub

Private Sub Option6_GotFocus()
BeginningDate.Visible = False
EndingDate.Visible = False
FromInspection_.Visible = False
ToInspection_.Visible = False
BeginningJob_.Visible = True
EndingJob_.Visible = True
End Sub

Private Sub Option6_LostFocus()
BeginningJob_.Visible = False
EndingJob_.Visible = False
End Sub

You have made the mistake of using the event of each toggle within the option group rather than use the option group itself

Here's a quick solution. Put an asterisk in the Tag property of every control you make either visible or invisible.

Code:
Private Sub fraMyOptions_AfterUpdate()
    Call NotVisible
    Select Case Me.fraMyOptions
        Case Is = 2
            Me.BeginningDate.Visible = True
            Me.EndingDate.Visible = True
        Case Is = 4
            Me.FromInspection_.Visible = True
            Me.ToInspection_.Visible = True
        Case Is = 6
            Me.BeginningJob_.Visible = True
            Me.EndingJob_.Visible = True
    End Select
End Sub

Private Sub NotVisible()
    Dim ctl As Control
    For Each ctl In Me
        If ctl.Tag = "*" Then
            ctl.Visible = False
        End If
    Next
End Sub

THe Select Case values of 2, 4, and 6 are those of the names of the option group you mentioned. The actual value of the frame might be different and the 2, 4, and 6 can be replaced with 1, 2, and 3.
 
Last edited:
Thanks

Short & sweet.... and works like a charm! Thanks...
Yes, I had the visible properties on the form set to no...... Thats why I couldnt understand why they showed up.
Thanks again for your help
 

Users who are viewing this thread

Back
Top Bottom