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

Greying Out a Button on a Form when there is no data below 2

Status
Not open for further replies.

DanAuber

IS-IT--Management
Apr 28, 2000
255
FR
I have a form that&nbsp;&nbsp;links to another via a field. Both forms are views of tables. The tables have a common field (hostname). I want the button that moves from the master form to the child form to be greyed out when there are no records in the Child table. I know I do this using VB Code attached to the On Current Property of the Main Form. I also know I need to use Me!ButtonCommand.Enabled = False.<br>But I can't seem to work out how to Embed the SQL.<br>It should look like this:-<br><br>On Current - Run a select count(*) from Child_table where hostname = [current_hostname];<br>If the result of this = 0 then Me!ButtonCommand.Enabled = False. Otherwise it is True.<br><br>I can't quite figure out the VB and embedded SQL I need for this - can anyone help with this ??
 
Try something like this:<br><br>Private Sub Form_Current()<br>If DCount(&quot;[id]&quot;,&quot;
&quot;,&quot;[id]=forms!frmname!id&quot;)= 0 Then<br>&nbsp;&nbsp;&nbsp;&nbsp;Forms!frmname!button.Enabled = False<br>Else<br>&nbsp;&nbsp;&nbsp;&nbsp;Forms!frmname!button.Enabled = True<br>End If<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>End Sub<br><br>Where frmname is the name of the main form, table is the name of the record source for the subform. Id is the name of your linking field.&nbsp;&nbsp;There are some more concise methods but this works well.<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top