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

Make CMD button visible if comments exist

Status
Not open for further replies.

MaggieLeatherman

Programmer
May 9, 2004
59
US
Hi, I have a form with Area records that has a subform that contains Material records. Each Material record has a column to store comments. I put a command button on the subform to open up another form to view/edit/add the Material comments.
This "VIEW" command button is seen on every record whether there's a comment associated with it or not...

Is there a way to make the "VIEW" command button visible ONLY if the there are comments?
Thanks, Maggie
 
This might do..

Behind your subform_Open() event
Code:
Dim varComments as Variant
  strComments = Me.txtComments.Value

   If IsNull(strComments) Then
     Me.cmdVIEW.Visible = False
   End If


~Melagan
______
"It's never too late to become what you might have been.
 
Sorry...got distracted and forgot to complete my code =)

Code:
Dim varComments as Variant
  strComments = Me.txtComments.Value

   If IsNull(strComments) Then
     Me.cmdVIEW.Visible = False
   Else
     Me.cmdVIEW.Visible = True
   End If

I also noticed that the form's open event is probably not the best place to put this code. I'm actually not sure which event would be most suitable. You're wanting this button to dynamically appear and disappear as you're browsing through records, correct?

~Melagan
______
"It's never too late to become what you might have been.
 
Ahh I found it - On Current event is what you need, assuming the above post is correct in it's assumptions.

Code:
Private Sub Form_Current
Dim varComments as Variant            
  varComments = Me.txtComments.Value  'Your column for comments.

   If IsNull(varComments) Then        'Test for null value
     Me.cmdVIEW.Visible = False       'make button invisible
   Else
     Me.cmdVIEW.Visible = True        'make button visible
   End If

Also fixed discrepancies between "strcomments" and "varcomments". Too late in the day =)

~Melagan
______
"It's never too late to become what you might have been.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top