OK I am trying to create buttons on my form for users to work with the records in a table. I have Enter, Change, Save, Cancel, and Main Menu buttons. The key is I want to enable/disable buttons depending on the state of the record. So for example if the user presses the "Change" button, all the remaining buttons are disable except "save" and "cancel".
The code I have create *(SO FAR)* to the function is at the bottom of this post. This is comming along OK, but there just seems like there could an easier way.
I got to looking at the wizard and how it creates buttons and I ran across this code:
I was unable to find any documentation on this "command" method. I was interested in using it if it would make my life easier :).
*Any* tips regarding creating a buttons for this type thing is appreciated. Also any information on the command method is appreciated. Thanks :)
The code I have create *(SO FAR)* to the function is at the bottom of this post. This is comming along OK, but there just seems like there could an easier way.
I got to looking at the wizard and how it creates buttons and I ran across this code:
Code:
topparent.command("RECORD_COMMIT")
*Any* tips regarding creating a buttons for this type thing is appreciated. Also any information on the command method is appreciated. Thanks :)
Code:
FUNCTION TestButton AS V (ButtonPressed_par AS C, form_par AS P ) Dim CurrentFormMode as C CurrentFormMode = form_par.mode_get() select case CurrentFormMode = "VIEW" select case ButtonPressed_par = "btnEnter" 'put the form in Enter Mode 'disable buttons form_par:btnEnter.Disable() form_par:btnChange.Disable() form_par:btnMainMenu.Disable() 'Enable save and cancel buttons form_par:btnCancel.Enable() form_par:btnSave.Enable() end case ButtonPressed_par = "btnChange" 'Put the form in Change Mode 'disable buttons form_par:btnEnter.Disable() form_par:btnChange.Disable() form_par:btnMainMenu.Disable() 'Enable save and cancel buttons form_par:btnCancel.Enable() form_par:btnSave.Enable() end case ButtonPressed_par = "btnMainMenu" 'Close the form form_par.close() Case else 'the user pressed an invalid button 'Reset the buttons to what they should be in "VIEW" mode. form_par:btnEnter.Enable() form_par:btnChange.Enable() form_par:btnMainMenu.Enable() form_par:btnCancel.Disable() form_par:btnSave.Disable() end end select case CurrentFormMode = "ENTER" .OR. CurrentFormMode = "CHANGE" select case ButtonPressed_par = "btnSave" 'We try to save the record, if successful on error goto SaveErrorHandler IF CurrentFormMode = "ENTER" then end if IF CurrentFormMode = "CHANGE" then form_par.change_end(.T.) end if 'we go back to view mode and reset the buttons to what they should be in VIEW mode form_par:btnEnter.Enable() form_par:btnChange.Enable() form_par:btnMainMenu.Enable() form_par:btnCancel.Disable() form_par:btnSave.Disable() end SaveErrorHandler: case ButtonPressed_par = "btnCancel" 'We cancel the new/editted record form_par.cancel() 'we go back to view mode and reset the buttons to what they should be in VIEW mode form_par:btnEnter.Enable() form_par:btnChange.Enable() form_par:btnMainMenu.Enable() form_par:btnCancel.Disable() form_par:btnSave.Disable() end case Else 'the user pressed an invalid button 'Reset the buttons to what they should be in "Enter" mode. end select case CurrentFormMode = "QUERY" form_par.query_exit() 'kill query mode 'then recall the function with the parameters and quit case CurrentFormMode = "FIND" form_par.find_exit() 'Tell the user they were in query mode and exit case else 'Serious error, The form is in a state that Alpha says it cant get into. end select END FUNCTION
Comment