how to make command button not visible.

J

Jedireg

I have a form which has a command button on it that I want to make
invisible. the code is as below.


Private Sub cmdUseJoBlocks_Click()
' some other useless code here.

cmdUseJoBlocks.visible = False
End Sub



the problem is that when I run this code it errors out saying
" Run-time error '2165': You can't hide a control that has the focus."


any help would be greatly appreciated.
 
R

Roger Carlson

The problem is straight forward. You can't use code behind a control to
hide the control itself. You have to put the code somewhere else, but since
I don't know what the form is doing or why the button needs to be hidden, I
can't really advise.

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 
F

fredg

I have a form which has a command button on it that I want to make
invisible. the code is as below.

Private Sub cmdUseJoBlocks_Click()
' some other useless code here.

cmdUseJoBlocks.visible = False
End Sub

the problem is that when I run this code it errors out saying
" Run-time error '2165': You can't hide a control that has the focus."

any help would be greatly appreciated.

Just move the focus somewhere else first.

Private Sub cmdUseJoBlocks_Click()
' some other useless code here.
Me.[SomeOtherControl].SetFocus
cmdUseJoBlocks.visible = False
End Sub
 
J

Jedireg

Roger said:
The problem is straight forward. You can't use code behind a control to
hide the control itself. You have to put the code somewhere else, but since
I don't know what the form is doing or why the button needs to be hidden, I
can't really advise.


The form is gathering user input which is used with info from several
tables to generate a machine setup sheet. the command button concerned
is used to tell the code that the user wants to use the calculated jo
block set instead of a master disc for a given size. When the button is
clicked I want it to pull the calculated values for the jo block stack
from several labels on the form and give them to the generator for the
machine setup sheet. Once the user clicks on the button I want the
button to be hidden. Below is the full code for the click event of this
button:

Private Sub cmdUseJoBlocks_Click()
Form_frmSizeSheet.lblMasterNo.Caption = "N/A"
Form_frmSizeSheet.lblJB1.Caption = lblJB1.Caption
Form_frmSizeSheet.lblJB2.Caption = lblJB2.Caption
Form_frmSizeSheet.lblJB3.Caption = lblJB3.Caption
Form_frmSizeSheet.lblJB4.Caption = lblJB4.Caption
Form_frmSizeSheet.lblJB5.Caption = ""
Form_frmSizeSheet.lblJB6.Caption = ""
Form_frmSizeSheet.lblMasterSize.Caption = lblJBTotal.Caption
Form_frmSizeSheet.lblGageSetting.Caption = Format(0, "0.0000")
Form_frmSizeSheet.lblMasterSection.BackColor = &HFFFFFF
Form_frmSizeSheet.lblJBSection.BackColor = RGB(167, 218, 78)
ggReadyToPrint
End Sub

Function ggReadyToPrint()
cmdUseJoBlocks.Visible = False <------- depending on which button
cmdUseMaster.Visible = False <------- is clicked one of these
lstMasters.Visible = False will error out.
lblJB1.Visible = False
lblJB2.Visible = False
lblJB3.Visible = False
lblJB4.Visible = False
lblJBTotal.Visible = False
txtShopOrder.Visible = True
cmdGenerateSheet.Visible = True
lblJoBlocks.Visible = False
lblPlus.Visible = False
lneSum.Visible = False
txtShopOrder.Visible = True
End Function
 
J

Jedireg

fredg said:
I have a form which has a command button on it that I want to make
invisible. the code is as below.

Private Sub cmdUseJoBlocks_Click()
' some other useless code here.

cmdUseJoBlocks.visible = False
End Sub

the problem is that when I run this code it errors out saying
" Run-time error '2165': You can't hide a control that has the focus."

any help would be greatly appreciated.

Just move the focus somewhere else first.

Private Sub cmdUseJoBlocks_Click()
' some other useless code here.
Me.[SomeOtherControl].SetFocus
cmdUseJoBlocks.visible = False
End Sub


I tried moving the focus to the form itself but that did not work.
 
J

Jedireg

Jedireg said:
fredg said:
I have a form which has a command button on it that I want to make
invisible. the code is as below.

Private Sub cmdUseJoBlocks_Click()
' some other useless code here.

cmdUseJoBlocks.visible = False
End Sub

the problem is that when I run this code it errors out saying
" Run-time error '2165': You can't hide a control that has the focus."

any help would be greatly appreciated.

Just move the focus somewhere else first.

Private Sub cmdUseJoBlocks_Click()
' some other useless code here.
Me.[SomeOtherControl].SetFocus
cmdUseJoBlocks.visible = False
End Sub


I tried moving the focus to the form itself but that did not work.


I moved the focus to a textbox and it worked perfectly. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top