Hide command button on lost focus

Seems simple, but I haven't been able to crack this one.

I've searched and haven't found an obvious answer.

I want to hide a command button after it loses focus. I've tried placing this code on the On Lost Focus and On Exit events of the command button.


	Code:
	Me.cmdName.Visible = False

I get the 2165 error, 'Can't hide a control that has a focus'.

I guess one solution would be to force the focus to another control first, however, "how do I know what control the user is attempting to move the focus to?"


Post your answer or comment

comments powered by Disqus
I have a simple database that has a command button on each record that can enable the user to delete that particular record. However this is quite easy to do and may be clicked accidentally. Is there any way I can hide or make the command button harder to use so only certain users know how to use or find it.

Any help would be greatly appreciated.

Thanks.

Hi Guys. I want to Display a command button on a form dependent on the value of another control.

I have a Main Form: frmSalesOrders and a Sub Form frmSalesOrderDetails

I have a command cmdSpecialInvoice on frmSalesOrders.
On Form Load I hide this.

However if the user selects a MakeID from frmSalesOrderDetails with an ID of 61 I want the button to be visible.

I attempted to put this on the After Update Event of control 'MakeID'


	Code:
	If Forms!frmSalesOrderDetails!MakeID = 61 Then
    Forms!frmSalesOrders!cmdSpecialInvoice.Visible = True
     End If

I got an error stating could not find frmSalesOrderDetails?

That aside is it possible to do what I want?

Note:
MakeId is a combo. Takes its value from qryMakes if tht makes a difference.

Any ideas?
Cheers,
Phil.

Hello all. Here's my latest question. Is there a way make visible/hide a command button on an Access report based on the value of another field on the report?

Essentially, if Text1 is null, Command2.Visible = No. If Text1 is not null, Command2.visible = Yes

I've seen articles on the internet that address this with Forms but can't find a solution for reports.

Thanks

I have command buttons that receive focus based on a Tab Order. Right now it is difficult to tell that cursor has “landed” on the button. I checked the Properties list, but could not see anything that was specific to color selection. Is there a way to change the color of the button when it receives the focus (or some other event)?

Is it possible to put a command button on a report footer? I want to run a report and then export it to a snp file. I can get the snp file to creat at the same time as the preview but I would like to preview 1st then output to a snp file 2nd

Thanks for looking

Jim

I have a text box on a form with an 'On Lost Focus' procedure. I need this to work every time it loses focus but only seems to work on the first occassion of it losing focus.

Is this correct?
If so, how can I get it to work everytime it loses focus?

Hello, Everyone.
I have visited this forum frequently and got a lot of useful advice. I developed several small databases for my work but used mostly macros whenever I needed. The database that I'm working on right now is much more complex and I decided to try VBA because it provides more flexibility. So I'm pretty familiar with Access but have very little experience with VBA.
Long story short:
- I have a table with three columns(Id, LineNumber, Gtxt0). I have a form to input information into Gtxt0 (which is a paragraph on the report).
- The number of Gtxt0 is different for each record and I would like to create a command button on the form to add columns to a table if needed.
I don't know if this is clear enough, but so far I used sql statement to alter table but it returned an error because the table is bound to the form. I also do not know how to check if there are any fields available to input information for the same record prior to adding new field.

I use Access 2010 on Win 7 Enterprise.
Thanks in advance.

I have a main form that contains a sub form. On the main form I have a commad button that refreshes and requeries the sub form. I also have a command button that opens a popup form to add new contracts. What I would like to do is have the popup form execute the requery command button on the main from when the popup form is closed. Is this possible???

Is there a way to hide a button on a form if the current user does not have admin right set in security or is a member of a certain group in the db's security. I have a button I want to leave on a form for only users with admin rights or a member of a group called exportsecure. I've set the security in the db. Is this possible? Thanks very much..

I currently have a Command Button on Form A that opens Form B. You enter information on Form B and then click another Command Button named Close Form. This closed Form B and updates records into a Table of which Form A is attached. When I click the Close Form Button on Form B I would like for Form A to be Refreshed?? so the information that was added in Form B will not be present in the appropriate Dropdowns in Form A. Currently I have to close Form A & reopen it for the information to be available. Any ideas?

I have a situation where I have two fields RankingNo and SpecialNo I have placed 2 command buttons on the form header of the subform to switch between the ranking order and a numeric order (the SpecialNo). This works perfectly on the subform but when I open the main form I get a message "Can't find the Form" I have tried moving the buttons to the Main form with the same result. That includes changing the form name in the code to that of the main form. The forms are linked by the field SpecialSectionID.

Private Sub SpecialNum_Btn_Click()
On Error GoTo Err_SpecialNum_Btn_Click
Forms![Specials Setup for Ranking Subform].OrderBy = "Specials.[SpecialNo]"
Exit_SpecialNum_Btn_Click:
Exit Sub

Err_SpecialNum_Btn_Click:
MsgBox Err.Description
Resume Exit_SpecialNum_Btn_Click

End Sub

Can anyone help with something that will allow me to be able to use these controls when the main and subform are open. Thanks

Hello everybody!

I have a switchboard where everyone logs into the datbase and is taken to there indivual mini switchboards. what I want to know is there a way i can disable a close command button on a form and have the person use another close button so that they can exit out of that form to where i want them to go ie back to there own personal switchboards.

I hope that made sense.

Thanks Richard

Hi

In my databse, When I print a report using command button on form,
I want to close that form instantly i.e By Clicking Single Button Report
should be print simultaniously closing the same form

Immediate help requires

Thanks in advance

how do you hide close button on form? your help would be great...! thanks

I am working on a system I did not develop in Access 2010. A form (that was called by another form) generates an error when moving from any field that contains an On Lost Focus event.

The Access error message is: The expression On Lost Focus you entered as the event property setting produced the following error: User-Defined type not defined.

Here is the Private Sub FistName_LostFocus() code from one such field:

	Code:
	Private Sub FirstName_LostFocus()
If IsNull(Me!FirstName) Then
    MsgBox "Must enter First Name"
    Me!LastName.SetFocus
    Me!FirstName.SetFocus
Else
   Me!FirstName.Value = StrConv(Me!FirstName, vbProperCase)
End If
End Sub

Reading elsewhere it seems that the desired method is to use BeforeUpdate/AfterUpdate. When I move the above code to a BeforeUpdate event and I leave the First Name blank I do not receive the message "Must enter First Name" but I receive an Access error: The expression Before Update you entered as the event property setting produced the following error: User-Defined type not defined.

Can anyone tell me

a) what is wrong with this code
b) what is the desired approach to edit checks of this nature

TIA for any help you can give.

Hi All...
I have a required field in my table.
I don't want the user to skip entering any data in there.
So In On Lost Focus:

If IsNull (Me.FieldName) Then
MsgBox ""
DoCmd.Cancelevent
Else
..............
End If
But still this field can be skipped smoothly.
I tried Before and After Update but still the same
Any help please...
Thank you

I have a form which I want to be printed, and as forms are not designed for printing I have designed an identical report (with subreports) displaying the data in all the fields on the form, for all records.

I have put a command button on the form with the caption "Print this page", but am not sure of the code to use to make it print the report for ONLY that page, not them all.

Any ideas?

I am at a stand still; PLEASE HELP ME!

I have been researching this problem and trying many different things, but I cannot get it to work! Here is what I want to happen:

When I move my cursor from a text box (On Lost Focus), I would like the corresponding table to be checked for the value (a purchase order number). If this PO number already exists in my table, I would like an error to pop up. If it does not already exist, I would like to continue entering data in my form.

This should operate in the background and I would like that this happen as soon as I move away from the text box. This value acts as the Primary Key for the table, and will throw an error if the PO number already exists after I try to move away from the RECORD. But I want it to happen when I enter the PO number (or immediately after - when I move away from the form field) in order to save the time and effort of entering redundant data.

Does this make sense? I have tried using ADO to run a query and check the length of the resulting recordset, but I can't seem to get it to work. (That is, if the recordset contains records, this record must already exist; If the recordset is at EOF then continue entering data.) I am familiar with ADO in ASP, but not VBA.

Does anyone have any recommednations? Please help!

Thanks in advance.

I thought I could use a command button on a form to run another application. In my table in record contains several maps. I want to build a form that identifies each map in the record and, when I click on the command button, opens the file containing the map (a *.pdf file). There appears to be a substantial amount I do not know.

I want a calculation for "textbox1 (called from a module function) to execute when the value in "textbox2" is entered or changed. Which event for "textbox2" is the best one to call the function; After Update, On Change, On Exit, On Lost Focus?

Is there a disadvantage to making all of these events call the function?

I need some help... I have created a wonderful switchboard but need to add some security to it. There is about 50 users in this DB and I tried to use the Security wizard to set everybody up...It created a huge problem! It did not just secure this database but it secured every database that was on that server since it was created on it. I need to create a password for the command buttons on the switchboard. So that when the button is clicked it prompts for a password before opening a table, query or form. I am clueless on how to do this. I keep running into a dead end. I need some major help! Please! Please! Please!

I want to add a command button on form that export my access queries,or table,or report into .html format.

How to create a command button on a form that designates which button was clicked in the table that the entry is made?

Background - We orignally had 9 spreadsheets, I combined all the spreadsheets into one table, because all the fields are the same, we will still have 9 people inputting data from different departments.

Date Started
Date Ended
Activity
Detail
Author
Title
Subject
Charged to (text field)
Comments (memo field)

I want to add another field (User1) if User1 button is clicked or (user2 if another button). I need to be able to allow them to run a query based on the entries that each indivdual entered that week so they can add/change entries as needed but only for their own input.
Any help would be appreciated.

I have a command button on each record of a multiple item form. I need to disable the command button on some but not all records based on data on a field on that record. Is this possible?


Not finding an answer? Try a Google search.