By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,486 Members | 2,061 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,486 IT Pros & Developers. It's quick & easy.

Hide Command Button if Field Is Null

P: 12
Hi,

I have a command button on a form that the user can use to browse to a file and the user can select that file and a hyperlink to that file is stored in a txtfield for that record.

I then have a command button that a user can click to open and view the associated file.

This all works fine. BUT:

I would like the command button that allows the user to view the file to be hidden if no hyperlink was added. In other words the txtfield for the hyperlink IsNull.

Here is what I have tried with no luck:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub txtSelectedFile_AfterUpdate()
  3. If (Me.[txtSelectedFile]) = IsNull Then
  4. cmdExplore.Visible = False
  5. Else
  6. cmdExplore.Visible = True
  7. End If
  8.  
  9. End Sub
  10.  
  11.  
Thank you!!!
Jan 12 '10 #1

✓ answered by alnino

Thank you for all of the responses.

It now works with a combination of code, using the Form_Current():
Thank you!!!
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Form_Current()
  3.  
  4.     If Nz(Me!txtSelectedFile, "") = "" Then
  5.         Me!cmdExplore.Visible = False
  6.     Else
  7.         Me!cmdExplore.Visible = True
  8.     End If
  9.  
  10. End Sub
  11.  
  12.  

Share this Question
Share on Google+
14 Replies


MMcCarthy
Expert Mod 10K+
P: 14,534
Try this ...

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub txtSelectedFile_AfterUpdate() 
  3.     If NZ(Me.[txtSelectedFile], "") = "" Then 
  4.         cmdExplore.Visible = False 
  5.     Else 
  6.         cmdExplore.Visible = True 
  7.     End If 
  8.  
  9. End Sub 
  10.  
  11.  
Jan 12 '10 #2

P: 12
Thank you for the reply... But no luck. Command Button still visible when field is blank.
Jan 12 '10 #3

MMcCarthy
Expert Mod 10K+
P: 14,534
Add the Me! reference just in case there is a problem with the button name.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub txtSelectedFile_AfterUpdate() 
  3.     If NZ(Me!txtSelectedFile, "") = "" Then 
  4.         Me!cmdExplore.Visible = False 
  5.     Else 
  6.         Me!cmdExplore.Visible = True 
  7.     End If 
  8.  
  9. End Sub 
  10.  
  11.  
You should always add it anyway and if you run the debug option it will tell you if there is a problem with the reference. Otherwise check the textbox txtSelectedFile and see if it is holding any blank spaces.
Jan 12 '10 #4

nico5038
Expert 2.5K+
P: 3,072
I created a hyperlink table field named "x" and used in the InCurrent event:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2. Me.x.Visible = Not IsNull(Me.x)
  3. Me.Repaint
  4. End Sub
  5.  
And my x field was invisible when Null...

Nic;o)
Jan 12 '10 #5

P: 12
Thank you for all of the responses.

It now works with a combination of code, using the Form_Current():
Thank you!!!
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Form_Current()
  3.  
  4.     If Nz(Me!txtSelectedFile, "") = "" Then
  5.         Me!cmdExplore.Visible = False
  6.     Else
  7.         Me!cmdExplore.Visible = True
  8.     End If
  9.  
  10. End Sub
  11.  
  12.  
Jan 13 '10 #6

P: 12
Thank you all for your help....

One last question:

The screen only refreshes if I advance a record and then come back. Is there a way to "refresh" or "repaint" when this txt field is either null or contains data?

I am not sure what event to use or which field to call for such an event.

Thank you
Jan 14 '10 #7

MMcCarthy
Expert Mod 10K+
P: 14,534
In the after update event of the txtSelectedFile textbox try ...

Expand|Select|Wrap|Line Numbers
  1. Form_Current
  2.  
This will re-run any and all code in the forms current event.
Jan 14 '10 #8

P: 12
I have tried this but no luck

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtSelectedFile_AfterUpdate()
  2. Form_Current
  3. End Sub
  4.  
Jan 14 '10 #9

MMcCarthy
Expert Mod 10K+
P: 14,534
Me.Refresh will clear out any unbound text boxes. If that is what you are trying to do. If you explain what it is you want to happen I might be able to help better.
Jan 14 '10 #10

P: 12
msquared,

I have command button on a form that allows a user to browse to a file (doc, pdf, etc..)
The user chooses that file and a hyperlink for that file is stored in a txt field for the table

Then on the form there is a command button that allows the user to click and open the hyperlinked file.

Currently it is set up so if the hyperlink field is empty, the command button to view a file is not visible

This all works fine.

The ONLY issue is if:
The user clicks and adds the hyperlink; the “view” button is not visible until the user advances one record on the form and then goes back to the record in question.
Jan 14 '10 #11

MMcCarthy
Expert Mod 10K+
P: 14,534
Put the Form_Current command at the end of the code that adds the hyperlink to the field. It doesn't work in the AfterUpdate event because you never tab into that field so the event never triggers.
Jan 14 '10 #12

P: 12
msquared,

I have put the Form_Current at the ned of the code to add the hyperlink... since no luck making the "View File" command button visible unless advance record and go back...umm...

Expand|Select|Wrap|Line Numbers
  1. Private Sub CmdBuildingAdd_Click()
  2.  
  3. Me!txtSelectedFile = BrowseFiles()
  4.    variable = Me!txtSelectedFile
  5.  
  6. Form_Current 
  7.  
  8. End Sub
  9.  
Jan 15 '10 #13

TheSmileyCoder
Expert Mod 100+
P: 2,321
While what you have posted will certainly work, it might clutter up things latter if you wish to add other code to your Form_Current that you might not like running after uses adds his hyperlink.

Instead add a procedure to your form:
Expand|Select|Wrap|Line Numbers
  1. Private Sub setLinkVis()
  2.     If Nz(Me!txtSelectedFile, "") = "" Then 
  3.         Me!cmdExplore.Visible = False 
  4.     Else 
  5.         Me!cmdExplore.Visible = True 
  6.     End If 
  7. End Sub
Then change your code to:
Expand|Select|Wrap|Line Numbers
  1. Private Sub CmdBuildingAdd_Click() 
  2.  
  3. Me!txtSelectedFile = BrowseFiles() 
  4.    variable = Me!txtSelectedFile 
  5.    call setLinkVis
  6.  
  7. End Sub 
And in your Form_Current:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current() 
  2.    call setLinkVis
  3. End Sub 
Jan 15 '10 #14

P: 12
TheSmileyOne,

That did it. THANKS!!!
Jan 15 '10 #15

Post your reply

Sign in to post your reply or Sign up for a free account.