Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

access 2007 need to clear unbound text box

Posted on 2015-02-08
11
50 Views
Last Modified: 2016-05-22
I have an unbound text box in a form that I use to go to a particular record. What I do is enter a part of a person's last name in the text box and then press a button next to it which reads the text in the text box and then takes me to the first record that matches the partial text string. What I want to do is the next time I go to that unbound text box to enter a new text string I would like to have the text box cleared first.
0
Comment
Question by:Starbuck67
  • 5
  • 4
11 Comments
 
LVL 29

Expert Comment

by:IrogSinta
ID: 40597173
In the textbox's OnEnter event, add the following:
Me.NameOfTextbox = Null

Ron
0
 
LVL 7

Expert Comment

by:Robert Sherman
ID: 40597176
You could put the following code into the "Got Focus" event, changing "Text1" for the name of the text box you want to clear.  Then, whenever you enter that text box, it will clear whatever is in there:

Me.Text1.Value = ""

Open in new window

0
 

Author Comment

by:Starbuck67
ID: 40597204
IrogSinta

Do you mean that I should type "Me.NameOfTextbox = Null" in the OnEnter Box on the OnEnter line?

Robert Sherman

Again do I type your suggestion on the GotFocus line?
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:Starbuck67
ID: 40597225
IrogSinta

I did as you suggested (see attachments) and ended up with an error
Access-2007-2-8-15---2.jpg
Access-2007-2-8-15---3.jpg
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 40597249
When you click on the On Enter property, you will see two buttons appear to the right.  One with a down arrow and the other with ellipses.  You could do one of two things.
Click on the down arrow, select [Event Procedure], then click on the ellipses.
Click on the ellipses, select Code Builder
In the code window that opens up, add the code I suggested.  It should look like this:
Private Sub FindLname_Enter()
    Me.FindLname = Null
    
End Sub

Open in new window

Ron
0
 

Author Comment

by:Starbuck67
ID: 40597267
IrogSinta

I entered the code as shown on the attached image. When I click in the unbound text box, the existing text does not go away.
Access-2007-2-8-15---4.jpg
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 40597330
Does the On Enter property of the textbox say [Event Procedure]?
0
 

Author Comment

by:Starbuck67
ID: 40597427
Yes
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 40597521
The problem is that you use the method Screen.PreviousControl.Setfocus which sets the focus to the FindLname textbox.  Since the textbox already has the focus, the OnEnter event does not fire.

Another issue I see is your use of DoCmd.RunCommand accmdFind.  This will not find the name you have in your textbox.  All this command does is bring up the Find Dialog Box (similar to pressing CTRL-F on your keyboard).  You probably meant to use DoCmd.FindRecord instead.  However, take note that FindRecord set to acEntire will stop as soon as it finds the string inside your textbox, so that textbox needs to be cleared first before doing the find.  Your whole code could simply be replaced with the following:
Private Sub Find_Click()
    Dim strFindThis As String
    
    strFindThis = Me.FindLname
    Me.FindLname = Null
    DoCmd.FindRecord strFindThis, acAnywhere, False, acSearchAll, True, acAll, True
    
End Sub

Open in new window


Now if you still want to have the textbox show your original find string and then clear out when you click on it, you can modify your code to this:
Private Sub Find_Click()
    Dim strFindThis As String
    
    strFindThis = Me.FindLname
    Me.FindLname = Null
    DoCmd.FindRecord strFindThis, acAnywhere, False, acSearchAll, True, acAll, True
    Me.FindLname = strFindThis
    
End Sub

Private Sub Lname_Enter()
    Me.FindLname = Null
End Sub

Open in new window

0
 

Accepted Solution

by:
Starbuck67 earned 0 total points
ID: 40599710
I think I have found what the problem is. I noticed at the top of the screen the statement "Security Warning  Certain content in the database has been disabled" with a button called 'Options' next to it. Pressing that button leads to another dialogue box the is called 'VBA Macro' with a choice to either provide 'protection against unknown content' or to 'enable this content.'

When I choose the enable content, then the macro we have been working on was just fine
Access-2007-2-8-15---5.jpg
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question