If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
disable buttons and show which button was pressed
Dont know if this can be done.
I have three buttons on my form which open reports that print certificates for attendees. the buttoins are imaginatively called certificate1, 2, 3. the certificates are basically the same info but different design, I would like to keep a record of which certificate design I printed for each event which would be displayed on the form as a radio button, I would also like to disable the buttons that were not pressed. so when the form is opened up again you can only print certificates in the same design as originally printed. I presume I will need to add a field to the events table, but have no idea what to do next. I hope someone can help thanks Phil |
#2
|
|||
|
|||
disable buttons and show which button was pressed
Phil,
Add an integer field to the table underlying the form. If the form is based on a query, also add the field to the query. In form design view, add an option group bound to the new field with no default value, with values 1, 2, and 3. Either disable the control or set Locked and TabStop to No so that the user cannot change the value manually. In the OnClick event of each button and in the form's OnCurrent event, add the following lines: Select Case Me![YourOptionGroup] Case 1 Me![Certificate2].Enabled = False Me![Certificate3].Enabled = False Case 2 Me![Certificate1].Enabled = False Me![Certificate3].Enabled = False Case 3 Me![Certificate1].Enabled = False Me![Certificate2].Enabled = False End Select Sprinks "Phil" wrote: Dont know if this can be done. I have three buttons on my form which open reports that print certificates for attendees. the buttoins are imaginatively called certificate1, 2, 3. the certificates are basically the same info but different design, I would like to keep a record of which certificate design I printed for each event which would be displayed on the form as a radio button, I would also like to disable the buttons that were not pressed. so when the form is opened up again you can only print certificates in the same design as originally printed. I presume I will need to add a field to the events table, but have no idea what to do next. I hope someone can help thanks Phil |
#3
|
|||
|
|||
disable buttons and show which button was pressed
The only thing I would do differently would be to put your code in a function
and call it from each button's click event rather than having 3 copies of the same code in a module. "Sprinks" wrote: Phil, Add an integer field to the table underlying the form. If the form is based on a query, also add the field to the query. In form design view, add an option group bound to the new field with no default value, with values 1, 2, and 3. Either disable the control or set Locked and TabStop to No so that the user cannot change the value manually. In the OnClick event of each button and in the form's OnCurrent event, add the following lines: Select Case Me![YourOptionGroup] Case 1 Me![Certificate2].Enabled = False Me![Certificate3].Enabled = False Case 2 Me![Certificate1].Enabled = False Me![Certificate3].Enabled = False Case 3 Me![Certificate1].Enabled = False Me![Certificate2].Enabled = False End Select Sprinks "Phil" wrote: Dont know if this can be done. I have three buttons on my form which open reports that print certificates for attendees. the buttoins are imaginatively called certificate1, 2, 3. the certificates are basically the same info but different design, I would like to keep a record of which certificate design I printed for each event which would be displayed on the form as a radio button, I would also like to disable the buttons that were not pressed. so when the form is opened up again you can only print certificates in the same design as originally printed. I presume I will need to add a field to the events table, but have no idea what to do next. I hope someone can help thanks Phil |
#4
|
|||
|
|||
disable buttons and show which button was pressed
Klatuu,
That's a good idea. I think you meant "generalized procedure" rather than "function" as no return value is required. The code can also be simplified, due to the series of similarly named controls, to: For i = 1 to 3 Forms("YourForm").Controls("Certificate" & trim(str(i))).Enabled = (i = Me![YourOptionGroup]) Next i Sprinks "Klatuu" wrote: The only thing I would do differently would be to put your code in a function and call it from each button's click event rather than having 3 copies of the same code in a module. "Sprinks" wrote: Phil, Add an integer field to the table underlying the form. If the form is based on a query, also add the field to the query. In form design view, add an option group bound to the new field with no default value, with values 1, 2, and 3. Either disable the control or set Locked and TabStop to No so that the user cannot change the value manually. In the OnClick event of each button and in the form's OnCurrent event, add the following lines: Select Case Me![YourOptionGroup] Case 1 Me![Certificate2].Enabled = False Me![Certificate3].Enabled = False Case 2 Me![Certificate1].Enabled = False Me![Certificate3].Enabled = False Case 3 Me![Certificate1].Enabled = False Me![Certificate2].Enabled = False End Select Sprinks "Phil" wrote: Dont know if this can be done. I have three buttons on my form which open reports that print certificates for attendees. the buttoins are imaginatively called certificate1, 2, 3. the certificates are basically the same info but different design, I would like to keep a record of which certificate design I printed for each event which would be displayed on the form as a radio button, I would also like to disable the buttons that were not pressed. so when the form is opened up again you can only print certificates in the same design as originally printed. I presume I will need to add a field to the events table, but have no idea what to do next. I hope someone can help thanks Phil |
#5
|
|||
|
|||
disable buttons and show which button was pressed
By "generalized procedure", I assume you mean a Sub.
It really doesn't matter whehter you use a Sub or a Function. The only real difference is a Function returns a value. That doesn't mean you have to capture the value returned. I asked the same question in this group a year or so ago and was told by (I think) either Allen Browne or Douglas Steele that always using functions is not a bad idea. You can always return at least a boolean value to the calling procedure knows whether the call was successful or not. Seems reasonable to me. "Sprinks" wrote: Klatuu, That's a good idea. I think you meant "generalized procedure" rather than "function" as no return value is required. The code can also be simplified, due to the series of similarly named controls, to: For i = 1 to 3 Forms("YourForm").Controls("Certificate" & trim(str(i))).Enabled = (i = Me![YourOptionGroup]) Next i Sprinks "Klatuu" wrote: The only thing I would do differently would be to put your code in a function and call it from each button's click event rather than having 3 copies of the same code in a module. "Sprinks" wrote: Phil, Add an integer field to the table underlying the form. If the form is based on a query, also add the field to the query. In form design view, add an option group bound to the new field with no default value, with values 1, 2, and 3. Either disable the control or set Locked and TabStop to No so that the user cannot change the value manually. In the OnClick event of each button and in the form's OnCurrent event, add the following lines: Select Case Me![YourOptionGroup] Case 1 Me![Certificate2].Enabled = False Me![Certificate3].Enabled = False Case 2 Me![Certificate1].Enabled = False Me![Certificate3].Enabled = False Case 3 Me![Certificate1].Enabled = False Me![Certificate2].Enabled = False End Select Sprinks "Phil" wrote: Dont know if this can be done. I have three buttons on my form which open reports that print certificates for attendees. the buttoins are imaginatively called certificate1, 2, 3. the certificates are basically the same info but different design, I would like to keep a record of which certificate design I printed for each event which would be displayed on the form as a radio button, I would also like to disable the buttons that were not pressed. so when the form is opened up again you can only print certificates in the same design as originally printed. I presume I will need to add a field to the events table, but have no idea what to do next. I hope someone can help thanks Phil |
#6
|
|||
|
|||
disable buttons and show which button was pressed
Sorry new to this,
Thanks for this where would I put the code for it to be a generalsied procedure and then what code do i put in the on click procedure to call the code "Sprinks" wrote: Klatuu, That's a good idea. I think you meant "generalized procedure" rather than "function" as no return value is required. The code can also be simplified, due to the series of similarly named controls, to: For i = 1 to 3 Forms("YourForm").Controls("Certificate" & trim(str(i))).Enabled = (i = Me![YourOptionGroup]) Next i Sprinks "Klatuu" wrote: The only thing I would do differently would be to put your code in a function and call it from each button's click event rather than having 3 copies of the same code in a module. "Sprinks" wrote: Phil, Add an integer field to the table underlying the form. If the form is based on a query, also add the field to the query. In form design view, add an option group bound to the new field with no default value, with values 1, 2, and 3. Either disable the control or set Locked and TabStop to No so that the user cannot change the value manually. In the OnClick event of each button and in the form's OnCurrent event, add the following lines: Select Case Me![YourOptionGroup] Case 1 Me![Certificate2].Enabled = False Me![Certificate3].Enabled = False Case 2 Me![Certificate1].Enabled = False Me![Certificate3].Enabled = False Case 3 Me![Certificate1].Enabled = False Me![Certificate2].Enabled = False End Select Sprinks "Phil" wrote: Dont know if this can be done. I have three buttons on my form which open reports that print certificates for attendees. the buttoins are imaginatively called certificate1, 2, 3. the certificates are basically the same info but different design, I would like to keep a record of which certificate design I printed for each event which would be displayed on the form as a radio button, I would also like to disable the buttons that were not pressed. so when the form is opened up again you can only print certificates in the same design as originally printed. I presume I will need to add a field to the events table, but have no idea what to do next. I hope someone can help thanks Phil |
#7
|
|||
|
|||
disable buttons and show which button was pressed
Phil,
Let's learn from the MVPs and use a function. Since this function is specific to the form, place it in the form's Code module (where your event procedures reside). More general functions, like creating the words "one thousand and 30/100" from a number $1,000.30, would go in a global module (on the Module tab in the Database window). Function SetCommandButtons() as Boolean On Error Resume Next ' Or more elaborate error-handling here Dim i as Integer For i = 1 to 3 Forms("YourForm").Controls("Certificate" & trim(str(i))).Enabled = (i = Me![YourOptionGroup]) Next i ' Optional specific code to set a return value ' If SomeCondition Then ' SetCommandButtons = True ' Else ' SetCommandButtons = False ' End If End Function To use the function, call it from the three OnClick event procedures: Call SetCommandButtons Hope that helps. Sprinks "Phil" wrote: Sorry new to this, Thanks for this where would I put the code for it to be a generalsied procedure and then what code do i put in the on click procedure to call the code "Sprinks" wrote: Klatuu, That's a good idea. I think you meant "generalized procedure" rather than "function" as no return value is required. The code can also be simplified, due to the series of similarly named controls, to: For i = 1 to 3 Forms("YourForm").Controls("Certificate" & trim(str(i))).Enabled = (i = Me![YourOptionGroup]) Next i Sprinks "Klatuu" wrote: The only thing I would do differently would be to put your code in a function and call it from each button's click event rather than having 3 copies of the same code in a module. "Sprinks" wrote: Phil, Add an integer field to the table underlying the form. If the form is based on a query, also add the field to the query. In form design view, add an option group bound to the new field with no default value, with values 1, 2, and 3. Either disable the control or set Locked and TabStop to No so that the user cannot change the value manually. In the OnClick event of each button and in the form's OnCurrent event, add the following lines: Select Case Me![YourOptionGroup] Case 1 Me![Certificate2].Enabled = False Me![Certificate3].Enabled = False Case 2 Me![Certificate1].Enabled = False Me![Certificate3].Enabled = False Case 3 Me![Certificate1].Enabled = False Me![Certificate2].Enabled = False End Select Sprinks "Phil" wrote: Dont know if this can be done. I have three buttons on my form which open reports that print certificates for attendees. the buttoins are imaginatively called certificate1, 2, 3. the certificates are basically the same info but different design, I would like to keep a record of which certificate design I printed for each event which would be displayed on the form as a radio button, I would also like to disable the buttons that were not pressed. so when the form is opened up again you can only print certificates in the same design as originally printed. I presume I will need to add a field to the events table, but have no idea what to do next. I hope someone can help thanks Phil |
#8
|
|||
|
|||
disable buttons and show which button was pressed
Thanks for that it works great
thanks Phil "Sprinks" wrote: Phil, Let's learn from the MVPs and use a function. Since this function is specific to the form, place it in the form's Code module (where your event procedures reside). More general functions, like creating the words "one thousand and 30/100" from a number $1,000.30, would go in a global module (on the Module tab in the Database window). Function SetCommandButtons() as Boolean On Error Resume Next ' Or more elaborate error-handling here Dim i as Integer For i = 1 to 3 Forms("YourForm").Controls("Certificate" & trim(str(i))).Enabled = (i = Me![YourOptionGroup]) Next i ' Optional specific code to set a return value ' If SomeCondition Then ' SetCommandButtons = True ' Else ' SetCommandButtons = False ' End If End Function To use the function, call it from the three OnClick event procedures: Call SetCommandButtons Hope that helps. Sprinks "Phil" wrote: Sorry new to this, Thanks for this where would I put the code for it to be a generalsied procedure and then what code do i put in the on click procedure to call the code "Sprinks" wrote: Klatuu, That's a good idea. I think you meant "generalized procedure" rather than "function" as no return value is required. The code can also be simplified, due to the series of similarly named controls, to: For i = 1 to 3 Forms("YourForm").Controls("Certificate" & trim(str(i))).Enabled = (i = Me![YourOptionGroup]) Next i Sprinks "Klatuu" wrote: The only thing I would do differently would be to put your code in a function and call it from each button's click event rather than having 3 copies of the same code in a module. "Sprinks" wrote: Phil, Add an integer field to the table underlying the form. If the form is based on a query, also add the field to the query. In form design view, add an option group bound to the new field with no default value, with values 1, 2, and 3. Either disable the control or set Locked and TabStop to No so that the user cannot change the value manually. In the OnClick event of each button and in the form's OnCurrent event, add the following lines: Select Case Me![YourOptionGroup] Case 1 Me![Certificate2].Enabled = False Me![Certificate3].Enabled = False Case 2 Me![Certificate1].Enabled = False Me![Certificate3].Enabled = False Case 3 Me![Certificate1].Enabled = False Me![Certificate2].Enabled = False End Select Sprinks "Phil" wrote: Dont know if this can be done. I have three buttons on my form which open reports that print certificates for attendees. the buttoins are imaginatively called certificate1, 2, 3. the certificates are basically the same info but different design, I would like to keep a record of which certificate design I printed for each event which would be displayed on the form as a radio button, I would also like to disable the buttons that were not pressed. so when the form is opened up again you can only print certificates in the same design as originally printed. I presume I will need to add a field to the events table, but have no idea what to do next. I hope someone can help thanks Phil |
Thread Tools | |
Display Modes | |
|
|