473,399 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Hide Command Button if Field Is Null

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.  

14 22043
MMcCarthy
14,534 Expert Mod 8TB
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
alnino
12
Thank you for the reply... But no luck. Command Button still visible when field is blank.
Jan 12 '10 #3
MMcCarthy
14,534 Expert Mod 8TB
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
3,080 Expert 2GB
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
alnino
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
alnino
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
14,534 Expert Mod 8TB
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
alnino
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
14,534 Expert Mod 8TB
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
alnino
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
14,534 Expert Mod 8TB
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
alnino
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
2,322 Expert Mod 2GB
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
alnino
12
TheSmileyOne,

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

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

Similar topics

2
by: Xerxes | last post by:
Hi, can you tell me how I can make a <label> hidden? I have hidden the field after the label: var M_Hide = isNS4?'hide':'hidden'; var M_Show = isNS4?'show':'visible'; ..... <label...
10
by: DettCom | last post by:
Hello, I would like to be able to display or hide fields based on whether a specific Yes/No radio button is selected. This is in conjunction with a posting a just made here in the same group...
12
by: ATS | last post by:
I need to hide/reveal parts of a web page using javascript. I think I can do with using the <span> tag, but I've been away from it for a while and don't remember. Any pointers, examples?
2
by: gbb0330 | last post by:
hi all first i would like to thank PC Datasheet, i got so far because of him/her i need some help again i have this command button the on-click event procedure is
0
by: Lauren Quantrell | last post by:
I use the following code to create text edit fields and command buttons in my toolbars: Function CreateToolbarObject(myObjectType as integer) Dim newObject Select Case myObjectType Case 1...
4
by: John Boy | last post by:
Hi, Can anyone help. This is really doing my nut in. 3 years ASP exp. and now doing .DOT which is a step in the wrong direction. Basically I am left with the code of a guy who has left. When I...
7
by: FP | last post by:
I'm new to Java Script. I'm displaying comments people have made. Below each persons' comment I want to add 2 buttons "Reply" and "Amend". Clicking "Reply" would display an empty text field...
3
by: toodi4 | last post by:
I'm using a javascript that hides and unhides text based on a button click. It works great across static fields on a form. The problem I have is that I'm trying to hide and unhide various fields...
3
by: kevinpublic | last post by:
I have an item list for ordered products on a data grid in VS 2003. It's an ASP page running VB behind it. All detail lines display as well as all shipping charges. On the edit screen, we allow...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.