Change Look of cmdButton based on refreshed results

g-richardson

Registered User.
Local time
Today, 14:39
Joined
Mar 4, 2005
Messages
42
So I'm trying to get the look, caption and the result of a click on a command button based on the refreshed data contained in a subform. This needs to be dynamic in that as a new date on the form's calendar is selected, the results listed in the subform will change based on that date and I need the command button to refresh based on the new subform results.

I've been able to get my caption to change (attempting to get one thing done and then build on it), but I could only get it to change when the command button lost focus, but then it wouldn't change back.

So basic example.

cmd0 - caption = "Available", so if I clidk on the command button, a form will open for someone to claim the space. When the form closes, the subform on the mainform containing the cmd0 button will refresh to show the space is booked. Would like cmd0 - caption = "Booked".

This is the sample Code I've tried...My first attempt at my own code and not just modify what I see here so please be gentle :p...

Sample Code:

If Forms!frm_CubeLayout!sfrm_Booked.Form!Space = "Space 94" And Forms!frm_CubeLayout!sfrm_Booked.Form!BookDate = Forms!frm_CubeLayout.Form!BookDate Then
Me.cmd0.Caption = "Booked"
Else
Me.cmd0.Caption = "Available"
End If

End Sample Code:

My two questions; a) can this code do what I'm asking? b) where can I place the correct code to get it to read the current state of the subform?

Thanks for ANY help.
 
The code looks OK but it's a matter of where you put it to run, but not in the OnClick event.

Either
(A) start the form's timer (Me.timerinterval=100) and put the code there so it will run after the sub form has been requeried - search on line help on timerinterval
or
(B) put the code in the OnCurrent event of the subform, referring to parent form's button as Me.Parent.cmdButton
 
Thanks Cronk, I'll give that a try. After I posted this, I tried using the textbox with transparent cmd over the top. I was able to get the txt box to do exactly what I wanted it to do, but I needed to "select" the corresponding record in the subform for the txtbox to change. Should I expect a similar thing to happen when just working the command button? Is there a better strategy I might use like trying to set up a record set in vba? I guess I need to step through the results of the subform and when the desired result is encountered switch the appearence.

I think I'm getting ahead of myself. I'm going to give your suggestions a go tomorrow and see what I see. Thanks again for the suggestions. I'll let you know how it goes.
 
Hey Cronk, though your suggestions did not do what I am looking to do, it did give me an idea for something else that I was working on and I was able to make your suggestion about the timeinterval work to my advantage. Thanks for suggisting it.

I will keep plugging along with my original issue and think I'm going to head down the Record Set route and do something with looping (all new to me, but ready to step out of the comfort zone).

Thanks again for the feedback. It was helpful, just for a different thing. haha.
 

Users who are viewing this thread

Back
Top Bottom