Text Box Question

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

I have a text box on my form, can I have it blank until I click the cursor
in it to reveal its content


Thanks in advance.........Bob Vance
 
Hi Bob,

Strange request, but this should get you going...

Create two textboxes that are identical in size and shape. For the purposes
of this example, I named one of them txtBookTitle and the other one
txtHiddenTitle. I'm also using a field that is named BookTitle. Make the
appropriate substitutions in your case. Set the following attributes:

txtBookTitle
Visible: Yes
Control Source: leave blank (ie unbound)

txtHiddenTitle
Visible: No
Control Source: BookTitle

txtHidden
Visible: Yes
Width: 0
Height: 0
Back Color: Use the same value as the detail section
Special Effect: Flat
Border Color: Same as detail section
Fore Color: Same as detail section


Add the following procedures to the code module for this form:

Option Compare Database
Option Explicit

Private Sub Form_Current()
On Error GoTo ProcError

Me.txtHiddenTitle.Visible = Me.NewRecord
Me.txtBookTitle.Visible = Not (Me.txtHiddenTitle.Visible)
Me.txtHidden.SetFocus

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure Form_Current..."
Resume ExitProc
End Sub

Private Sub txtBookTitle_GotFocus()
On Error GoTo ProcError

Me.txtBookTitle = Me.txtHiddenTitle

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure txtBookTitle_GotFocus..."
Resume ExitProc
End Sub

Private Sub txtBookTitle_Exit(Cancel As Integer)
On Error GoTo ProcError

Me.txtBookTitle = ""

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure txtBookTitle_Exit..."
Resume ExitProc
End Sub

If you want to allow the user to edit an existing record, then add the
following procedure:

Private Sub txtBookTitle_BeforeUpdate(Cancel As Integer)
On Error GoTo ProcError

Me.txtHiddenTitle = Me.txtBookTitle

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure txtBookTitle_BeforeUpdate..."
Resume ExitProc
End Sub


Finally, position the two textboxes with exactly the same Left and Top
values, so that they are perfectly overlaying each other. The very small
txtHidden textbox receives focus (it's visible property must by Yes) when you
navigate between records. This way, the user is forced to click into the
txtBookTitle field in order to display the value.


Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
 
Bob,

As an alternative to Tom's excellent suggestion, you might try
Conditional Formatting. Select the textbox in design view of the form,
then select 'Conditional Formatting' from the Format menu. In the
'Default Formatting' panel, set it so that the text colour is the same
as the back colour. In the Condition1 box, select 'Field Has Focus',
and set the text colour as required.
 
Hi Steve,

That seems like a much easier than the method I suggested! Thanks.

I'd probably still go with the idea of the small txtHidden textbox, setting
focus to this control in the Form_Current event procedure, so that it would
force a person to either tab or click into the textbox that Bob wants to
leave blank.


Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
 
Steve I tried you system and I could not get it to work
still showed the names in the text box...Thanx Bob
 
Hi Bob,

I also tried Steve's suggestion, and it worked fine for me. Did you set the
Fore Color to match the Back Color for the textbox in question? For example,
in design view, I set the following properties for the textbox that should
appear blank:

Back Color 16777215
Fore Color 16777215

This is basically white on white. Then use Conditional Formatting to change
the font color to black for the condition "Field Has Focus".


Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

TextBox Question! 7
Text box to change Color! 9
Script for Text Box 6
Text Box Query! 1
Make a text box return blank if 1
Text Box Question 1
Text Box Question 8
Button to go to a Text Box or label 10

Back
Top