hide the button afte click on it

adsmmg

Registered User.
Local time
Today, 03:37
Joined
Nov 27, 2007
Messages
10
in the click event of th save button i put the code "cmdSave.enabled = false" or "cmdSave.visible=false" but it didnt work and there is a problem can you help me please. i want the user at certain condition can save and in the other vise save button and disappear.
 
Your code looks to be correct. Can you post your DB so we can look at it.
 
this is my delete code:

Private Sub cmdDelete_Click()
Dim strMessage As String
Dim intOptions As Integer
Dim bytChoice As Byte

strMessage = "Are you sure you want to Delete this Record?"
intOptions = vbQuestion + vbOKCancel
bytChoice = MsgBox(strMessage, intOptions)
If bytChoice = vbCancel Then
cmdDelete.SetFocus
Cancel = True
Else
DoCmd.RunCommand acCmdDeleteRecord

End If
End Sub​

and form :
Private Sub Form_Current()
lblTest_12.Caption = CStr(Me.Recordset.AbsolutePosition + 1) & " of " & Me.Recordset.RecordCount
If Me.Recordset.EOF Then MsgBox "??? ??? ?? ??? ??? ?? ?????"
End Sub
 
I am a little confused. Why have you posted your code cmdDelete when your problem was with cmdSave? It would be helpful if you can post the code for the button where the problem is.
 
i am so sorry cause i have two open thread .
the code fo save button is:
Private Sub cmdSave_Click()
If Me.Dirty Then
strconfrim = MsgBox("Do you want to save the new record?", vbYesNo, "Change Firm Details")
If strconfrim = vbYes Then

DoCmd.RunCommand acCmdSaveRecord
Me.Detail.BackColor = vbWhite
cmdNew.Caption = "new"
Command61.Enabled = True
Command62.Enabled = True
Command63.Enabled = True
Command64.Enabled = True
cmdSave.Visible = False
cmdDelete.Enabled = True
Ctl_cmdEdit.Enabled = True
cmdSearch.Enabled = True
Exit Sub
Else
Me.Undo
Me.AllowEdits = False
Me.Detail.BackColor = vbWhite
cmdNew.Caption = "new"
Command61.Enabled = True
Command62.Enabled = True
Command63.Enabled = True
Command64.Enabled = True
cmdDelete.Enabled = True
Ctl_cmdEdit.Enabled = True
cmdSearch.Enabled = True

End If
Else
MsgBox "there is nothing to save! "
End If


End Sub​
 
hey Rabbie ! can we have a live chat in yahoo?
 
You cannot disable or hide a button that still has focus. When you click on it, it automagically has focus. (Focus = it is the last thing selected and is displayed specially.) Find another control, perhaps some innocuous text box, and do a [othercontro].setfocus before attempting to hide the button.
 
i have a similar query on this matter, hide/unhide or enable/disable buttons onclick.

i have 4 buttons in my form, ADD, SAVE, UNDO & EXIT. as a default during creating these buttons, all of these buttons are enabled. now, this is what i want to happen once each one of them are clicked......

when loading the form:
buttons enabled should be: ADD & EXIT
buttons disabled should be: UNDO & SAVE

once ADD button is clicked:
buttons enabled should be: SAVE, UNDO & EXIT
button disabled should be: ADD

once SAVE button is clicked:
buttons enabled should be: ADD, UNDO & EXIT
buttons disabled should be: SAVE

Can anyone provide me with the event procedures on the OnClick event of these things or in any event procedures which could make these things happen.

thank you in advance to all the experts here. btw, i am new in ms access please bear with me.
 
I do this by defining a "state" variable behind the scenes and I have one more button, a HELP button. (Doesn't really do much except pop up an unbound form with a lot of words on it.) The key is it is the fifth button and is ALWAYS legal.

So behind each button, I would put ONE line of code that selects/sets/defines the state variable to represent one of those cases you described. Then call a single routine that does a few things...

Code:
Public Sub ReDoMyButtons(MyStateVar)
    [HelpMe].SetFocus
    Select Case MyStateVar
        Case 1
            [SaveMe].Visible = True
            [SaveMe].Enabled = True
            [CloseMe].Visible = False
            [CloseMe].Enabled = False
            ... etc.
        Case 2
            [SaveMe].Visible = False
            [SaveMe].Enabled = False
            [CloseMe].Visible = True
            [CloseMe].Enabled = True
            ... etc.
      Case 3 etc etc etc
    End Select
    Me.Repaint
End

This way you do not run into the issue of trying to disable a button you are currently using. The .SetFocus sees to that. Imagine, if you will, a Bugs Bunny cartoon where Bugs is being chased by some animal. So he goes out on a limb and starts sawing. The animal laughs until the branch stays up but the tree falls down - on the animal. That is what you trying to do by hiding a button that you just clicked. It only works in cartoons.

BTW, that question would have been better served by making a new thread. You might have gotten more answers more quickly. But it's OK, I had an answer.
 

Users who are viewing this thread

Back
Top Bottom