Solved

access 2007 need to clear unbound text box

Posted on 2015-02-08
11
40 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
 

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
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now