Enable/Disable Command Button

hudson426

Registered User.
Local time
Today, 17:24
Joined
Jun 19, 2009
Messages
28
Hi all

I'm having a problem with enabling and disabling a command button on a form. Here goes....

I have a form that has two fields on it

Name ----- Select
(Text) -- (Yes/No)

Jonathan Yes
Sue Yes
Alison Yes
David Yes

  • If all four records are selected (Yes), I want to disable the command button
  • If there is at least one record de-selected (No), I want the command button to be enabled.
Underneath the data, there is a count() control. This control is called Text14 (sum(iif([select]="Yes",0,1)

There is a macro assigned to the AfterUpdate property on the select field called Refresh (Runcommand --> Refresh). This ensures the record count in Text14 is updated as soon as the records are selected etc.

The command button I want to enable/disable is called Command4

I have the following code set in the forms OnCurrent property

Private Sub Form_Current()
If [Text14] > 0 = True Then
Me.Command4.Enabled = True
Me.Command4.ControlTipText = "Continue"
Else
Me.Command4.Enabled = False
Me.Command4.ControlTipText = "There must be at least one search criteria included"
End If
End Sub

The problem...

If all four records are selected (Yes), the record count in Text14 = 0 BUT the command button isn't disabled until the focus is moved to the previous record or to the next record.

What am I missing??

Any help would be greatly appreciated
 
You need to call like code from each of button update events.

Edit: I mean from each of the 'Select' field controls.
 
Can you possibly give me an example?
 
What kind of control are you using to capture the 'Selected'? Are you using a check box?
 
So every time the check box value changes run the same pc of code.
 
I can't. I need to have the macro (Refresh) to run before the code can run but that macro is assigned to the afterupdate event of the select (checkbox) property.

Is there a way to add a line of code to the one I am using (above) to refresh all the records before the code runs?

If so, what code do I need to add?
 
Move what ever the refresh macro does to code and put the 'enable/disable' code with it. I think you're heading off into an illogical tangent thinking you can somehow update all of the records to do something meaningful. Unless I'm missing something.
 
Thats what I asked.

Using the code above, how do I refesh all the records? Is there a line of code I can insert to do the same function as the macro (Runcommand --> Refresh) into the enable/disble code?

What code do I need to perform a record refresh?
 
Please excuse me for appearing anal but why do you need the refresh to begin with?
 
Don't apologise. In my original post, I detailed a control that counts the number of records that have been selected. I have found that unless you move to a previous or next record, the count function doesn't refresh. By adding a record refresh macro, the count is updated without the need to move from one record to the next. This is why I added and need this refresh macro. Because the refresh macro is added to the afterupdate event of the check box, I can't insert the enable/disable code there. If I can combine the two, then it will probably work.

Do you know how I can add a record refresh into the code in my original post? If so, what is it?
 
Duh! (Me)

Works a treat. It now does exactly what I want. I'm a bit of a newbie so please accept my many thanks for your help on this. I know it was a little painful but I am very grateful for yoru help.

Jonathan
 
Sorry I didn't realize it sooner - :)

Glad you have it working.
 

Users who are viewing this thread

Back
Top Bottom