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

Problems with .Visible

Status
Not open for further replies.

billheath

Technical User
Mar 17, 2000
299
US
I need to be able to show a command botton only when the form date is the same as today's date. I tried:
If Me.DateWkd <> Date Then
Me.New.Visible = False
End if

This doesn't work. So I tried:
If Me.DateWkd <> Date Then
Me.New.Transparent = True

This works, but the user can still click where the command button should be and activate the button. How can I make the button inactive when it is hidden?

I am using Access 2007. Thanks in advance - You guys are great!

 
Where are you running the code? Is it in the on Current or After Update of DateWkd or both?

I would try:
Code:
Me.NameOfCommandButton.Visible = (Me.DateWkd = Date)

Duane
Hook'D on Access
MS Access MVP
 
Bubba100: Yes, I called it "new"

dhookom: The code is running in the Form - On current.
 
djookom: Same problem. the Button is still visible. I even tried putting your statement first and then the Me. New.transprent = true after it. The button is inactive but still shows.
 
Do not call it new. New is a reserved word as in
Public myCollection as New Collection
or
Set myCollection = New Collection

Reserved words are bound to cause problems. Use a naming convention to avoid this such as "cmdNew"
Other names to avoid
date
time
public
private
form
control
dim
access
me
etc.
 
I changed it to cmdNew. It is still not working. The code now reads:

If Me.DateWkd <> Date Then
Me.cmdNew.Visible = (Me.DateWkd = Date)
Me.Refresh
Me.cmdNew.Transparent = True
Else
Me.cmdNew.Transparent = False
Me.cmdNew.Visible = True
End If

Thanks for your help
bill
 
can you put this line of code in an show us what it displays?

debug.print Me.dateWkd & " - " & date
 
When I go to the form for 9/11 it shows:9/11/2009 - 9/14/2009
 
You do not need any if then based on duane's code. Just

Me.cmdNew.Visible = (Me.DateWkd = Date)
Me.cmdNew.transparent = not(Me.DateWkd = Date)
 
Without the if statement, I get an invalid null when opening up today's form. The on open event checks for a date. If none it enters today's date.

I tried it with only the 2 statements and it still did not work
 
Help!! I have entered this like Majp suggested:
Me.cmdNew.Visible = (Me.DateWkd = Date)
Me.cmdNew.transparent = not(Me.DateWkd = Date)

When I open a form that is not dated today, the cmdNew button is disabled but still displayed. (I want it to be invisible).
When I open a form dated today, the button is enabled and visible. (That part is working).
Any suggestions would be greatly appreciated.
 
How about if you move the code to 2 places:

Form_Load()

and

DateWkd_AfterUpdate()

Does that change anything?

--

"If to err is human, then I must be some kind of human!" -Me
 
kjv1611: Sorry, it didn't change anything. Thanks for trying
 
My only other thought was to put the code in the locations I mentioned, but also change it to:
Code:
    If DateWkd = Date Then
        MsgBox "Yay!"
    Else
        MsgBox "Nay!"
    End If

2 other thoughts beyond that are:
1. Use < and > comparisons rather than equal, just in case somehow in the comparison, one is actually using one date/time notation, and the other something different.

2. Same possible problem, different solution - use the Format$() function to make sure thye are both formatted the same.

3. Same possible problem, yet a different solution - try some combinations using the datediff function. Something like:

If DateDiff(date1,date2) > 0 Then.... Else

--

"If to err is human, then I must be some kind of human!" -Me
 
probably when the form opens there is no value dateWkd thus it is null
thus this resolves to
Me.cmdNew.Visible = (Me.DateWkd = Date)
Me.cmdNew.Visible = null
which is an error

so how about

Me.cmdNew.Visible = nz(Me.DateWkd = Date)
Me.cmdNew.transparent = not(nz(Me.DateWkd = Date))

I would stick this in the on current event to handle both the loading and moving to new record.
 
Good ideas; When I step through the code, the statements are being evaluated properly. When visible should be false, it is. When transparent should be true, it is. It just doesn't seem to control the command button that it addresses.

I tried the "Yea" and "Nay" msgbox idea and the messages respond correctly. Confusing!!
 
I am testing for a no value in the datewkd field with an if statement before running the code:

If Not IsNull(Me.DateWkd) Then
Me.cmdNew.Visible = (Me.DateWkd = Date)
Me.cmdNew.Transparent = Not (Me.DateWkd = Date)

end if
 
Just so you know. If you set it invisible it is hidden and has no functionality. If you then set it transparent it will be invisible, but you still can click it. Is there a reason for setting it transparent? I can not think of one.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top