Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hide cmd button after clicked once - until manually reset 1

Status
Not open for further replies.
Oct 6, 2002
60
US
I have a command button that I want the user to be able to click only once and then be invisible, or until a checkbox is clicked that will reset the button to be visible. The problem that I am having is that once I close the form the button automatically becomes visible when opened again. Any help on how to accomplish this would be greatly appreciated.
Boomer
 
Boomer,
You could create a table with a single record, consisting of a single Yes/No field, then open the table and set the Yes/No value with code on your button's Click event. Then test for the value of the Yes/No in the form's OnLoad event, and set the visible property of the button accordingly. Post back if you need a code example.

HTH,

Ken S.
 
I would like to see a code example. I assume that you are talking about using a recordset but if there is an easier way I would like to know what you have in mind

Thanks for the quick response
Boomer
 
Hi, Boomer:

Yes, I was talking about using a recordset.

In the button's Click event:

Code:
Dim CurDB As DAO.Database
Dim Rs As DAO.Recordset
Dim SQLStmt As String

SQLStmt = "SELECT * FROM tblButtonState"
Set CurDB = CurrentDb()
Set Rs = CurDB.OpenRecordset(SQLStmt, dbOpenDynaset)

Rs.Edit
Rs!ButtonState = False
Rs.Update
Rs.Close

Me!chkMyCheckbox.SetFocus        'can't hide a control that has focus
Me!chkMyCheckbox = False         'chkbox should sync with button, right?
Me!btnMyButton.Visible = False

Set Rs = Nothing
Set CurDB = Nothing

And in the form's On Load event:

Code:
Dim CurDB As DAO.Database
Dim Rs As DAO.Recordset
Dim SQLStmt As String

SQLStmt = "SELECT * FROM tblButtonState"
Set CurDB = CurrentDb()
Set Rs = CurDB.OpenRecordset(SQLStmt, dbOpenDynaset)

Me!btnMyButton.Visible = Rs!ButtonState
Me!chkMyCheckbox = Rs!ButtonState

Rs.Close
Set Rs = Nothing
Set CurDB = Nothing

And in the checkbox's After Update event:

Code:
Me!btnMyButton.Visible = Me!chkMyCheckbox

Seems to me that using a checkbox to reset the button sorta defeats the purpose of not allowing a 2nd click of the button unless the checkbox does other stuff, too. But I'm guessing that's the case.

HTH,

Ken S.
 
Oops... try this in the checkbox's After Update instead:

Code:
Dim CurDB As DAO.Database
Dim Rs As DAO.Recordset
Dim SQLStmt As String

SQLStmt = "SELECT * FROM tblButtonState"
Set CurDB = CurrentDb()
Set Rs = CurDB.OpenRecordset(SQLStmt, dbOpenDynaset)

Rs.Edit
Rs!ButtonState = Me!chkMyCheckbox
Rs.Update
Rs.Close

Me!btnMyButton.Visible = Me!chkMyCheckbox

Set Rs = Nothing
Set CurDB = Nothing

What all this does is basically synchronize the state of the checkbox with the visible property of the button, and stores that state in a little table so it can be recalled when the form opens. But maybe you don't want the user to be able to toggle the button's visibility with the checkbox. Another option would be to hide or disable the checkbox until the button is clicked, i.e. make the visible or enabled property dependent on the button's state. Let me know if that's what you prefer and you need a code sample.

HTH,

Ken S.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top