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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make textbox not visible depending on other textbox

Status
Not open for further replies.

crisis2007

Technical User
Apr 2, 2007
114
US
I can not find the solution to this problem I am having. I have two text boxes (txt1 and txt2). They are on a main form to display the months of the respective dates that are called up from two subforms in the main form. The control source to
txt1 is: =[SF_TimeTypeD1].[Form]![ESDate]

txt2 is: =[SF_TimeTypeD7].[Form]![ESDate]

I have formated both textboxes to only show their respective months, not the entire date.

This works fine and both show the correct data. However I want txt2 to not be visible if they both show the same month.

I can't seem to find a solution. I have tried this in the OnOpen event (and tried in the OnCurrent event)of the main form but it does not work:

Private Sub Form_Open()
If (Me.Text1.Value = Me.txt2.Value) = True Then
Me.Text2.Visible = False
End If
End Sub


 
The may not have the same value. A format does not affect the underlying data. Try:

Me.Txt2.Visible=(Month(Me.txt1)<>Month(Me.txt2))
 
Thanks for replying. I tried your suggestion but I get an error message stating "Invalid use of Null
 
Hello Crisis

where does the invalid use of null happens, it is probably because one of the text boxes is empty.

your code is almost right
TRY
Code:
Private Sub Form_Open()
    Me.Text2.Visible = True
    If IsNull(Me.Text1) = False And IsNull(Me.Text2) = False Then
        If Month(Me.Text1) = Month(Me.Text2) Then
            Me.Text2.Visible = False
        End If
    End If
End Sub



.....
I'd rather be surfing
 
You can use Nz:

[tt]Me.txt2.Visible = (Month(Nz(Me.txt1, 0)) <> Month(Nz(Me.txt2, 0)))[/tt]

The above will mean that txt2 will not be visible if both are Null. You may wish to change this.
 
remou is right,

I just shot from the hip, should have taken more time

.....
I'd rather be surfing
 
That did make txt2 not visible if both dates were "January". Unfortunately it is still not visible if the two text boxes have different months.

 
set the default of txt2 to visible in the form open and then evaluate to see if the months are the same:

me.txt2.Visible = True
Me.txt2.Visible = (Month(Nz(Me.txt1, 0)) <> Month(Nz(Me.txt2, 0)))

If the user can change the date values of the text boxes:
Then you could use the same code in the lost focus events of the text boxes that would reevaluate if they have been changed.


.....
I'd rather be surfing
 
I am still getting the same result and have no idea why. I am guessing that it thinks the date values are null. I am also using MS Access 97 if that makes any difference.
 
try changing the code to evaluate the subform values

Code:
If Month(Nz([SF_TimeTypeD1].[Form]![ESDate], 0)) <> Month(Nz([SF_TimeTypeD7].[Form]![ESDate], 0)) Then
     Me.txt2.Visible = False
Else
     Me.txt2.Visible = True
End If

.....
I'd rather be surfing
 
When I place the code and try it, this makes txt2 visible despite what the month in txt1 is.
 
where are you putting the code?
Waht are all the ways these text box values can be adjusted.

.....
I'd rather be surfing
 
I am putting the code on the Open event of the main form. These text boxes just show the value of the respective dates (ESDate) from the two subforms. They are not supposed to be manipulated by the user.

I have 7 subforms in in the main form. The [ESDate] in each subform gets populated from a code in another form. So the form basically shows a week of dates. As the week can span into a second month, I needed two textboxes. The form would look somewhat like this to the user:
S M T W T F S
January / February 27, 28, 28, 30, 31, 01, 02

Overtime:
Comp Earned:
Sick:


The subforms would allow the user to place their respective times in hours under the correct date and day of the month.

I would design the input form differently however the boss wants the input form exactly like the paper form we use now.
Usually if the week does not span into a second month, the Month would appear once.
 
How are crisis2007 . . .

Data in the form is not considered valid until the forms [blue]On Load[/blue] event! Move the code there . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Hello AceMan1
I moved the code and still get the same result.
 
crisis2007 - you have to think of every situation where the first textbox might change it's value. On Open and/or OnLoad only happens once, when the form opens. OnCurrent happens when you move to a record.

The two most likely events where you will want to call your code is:

Form_OnCurrent
Text1_AfterUpdate

If you have the code in OnCurrent, you won't need it any longer in the OnOpen.

 
okay, I think the problem is where the date values are coming from.

Are the two month text box values being updated from another form as well.

I think that the code that runs in the on open event runs before values exist in the text boxes, because the external form assigning those values can not do that until the open event finishes(someone correct me if I am wrong). Therfore you need to place your code in some event that triggers after the on open event.

Try making the text boxes editable (for testing sake) and place the following code on the lost focus events for each text box, then change the date values and tab between them to trigger the code. If that works then you need to find a way to trigger your code after the form is open.
Code:
If Month(Nz([SF_TimeTypeD1].[Form]![ESDate], 0)) <> Month(Nz([SF_TimeTypeD7].[Form]![ESDate], 0)) Then
     Me.txt2.Visible = False
Else
     Me.txt2.Visible = True
End If

.....
I'd rather be surfing
 
Timer event springs to mind.

Unless there is a change in focus or data in the textbox then no event will be triggered. Try the following in 'on load' and the 'on timer' events.

Me.txt2.Visible = IIf (month(Nz(Me.Text1)) = month(Nz(Me.txt2)),true, False)




Ian Mayor (UK)
Program Error
Always make your words sweet and nice. Because you never know when you may have to eat them.
 
I appreciate everyone's help. I have tried about every event I can and still come up with the same result. However I used the code supplied by jordanking on a command button and still nothing happened. However when I removed the word "Month" from both ends of the <> in the code, and hit the command button it removed the second date. I wonder of this is not recognizing what "Month" is in the code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top