Solved

access 2007 need to clear unbound text box

Posted on 2015-02-08
11
57 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

Industry Leaders: 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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

724 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