Solved

access 2007 need to clear unbound text box

Posted on 2015-02-08
11
54 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
[X]
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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

733 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