hide a command button when...

hyousef

Registered User.
Local time
Today, 13:54
Joined
Jan 15, 2002
Messages
41
I have a subform in a form. In my form i have a combobox and a command button. When a user choose form the combobox then the data appears in the subform. Sometimes, when a user choose an item from the combobox, it doesn't return data or records.

what i want is to show the command button only if there is no data or record in the subform returned by a user selection from the combobox. in other words,hide the command button if there is a record in the subform.

Any help is appreciated.
 
On the On_Current event of your subform

If Me.RecordsetClone.RecordCount <1 Then
Me.Parent.NameOfCommandButton.Visible = False
Else Me.Parent.NameOfCommandButton.Visible = True
End If
Me.Parent.Repaint

You could also approach it from an After_Update event of your combo

HTH

[This message has been edited by Fizzio (edited 05-28-2002).]

[This message has been edited by Fizzio (edited 05-28-2002).]
 
Fizzio,
This is work with records but in my case:

when a user choose from the combobx and there is no record match the criteria then the subform doesn't open and it will not be shown...in this case i want the command button to appear so a user can add a new record. but if there is a record that match the criteria then the subform appears, then i don't need the command button to apear.

Thank you Fizzio,
 
What do you currently have in the After_Update of your combo or button that sets the criteria ?
 
ok, i have 2 syncronise combo boxes. in after update for the first one i have the following:
Private Sub cboBudgetRef_AfterUpdate()
cboActivityName = Null
cboActivityName.Requery
Me.Requery
End Sub
In the criteria box in my query i have:
[Forms]![EngineerAssignment]![cboBudgetRef]


in the second one:
Private Sub cboActivityName_AfterUpdate()
Me.Requery
End Sub
in the criteria box in my query i have:
[Forms]![EngineerAssignment]![cboActivityName]


when a user chooses the first and then the second combo...if there is at least one record that match the criteria then a subform appears with the data...if there is no record then the subform doesn't appear.

if the subform doesn't appear then i want a command button to apear.
 
You could try using a recordset eg

Combo2_AfterUpdate()

Dim Db as DAO.Database, Rs as DAO.Recordset
Set Db = CurrentDb
Set Db = Db.OpenRecordset("NameOfQueryThatSuppliesSubform", dbOpenSnapshot)
If Rs.RecordCount = 0 Then
Me.CommandButton.Visible = True
Else Me.CommandButton.Visible = False
End If
Set Rs = Nothing

Other Code you may have here
End Sub

[This message has been edited by Fizzio (edited 05-30-2002).]
 
Nop Fizzio, it didn't work...Can i email you my DB so you can have a look?
 

Users who are viewing this thread

Back
Top Bottom