Solved Placing a label behind text box

Nampara

New member
Local time
Today, 03:30
Joined
Feb 4, 2017
Messages
5
Hi I don't know if what I want is possible but here goes.

I have a large form and would like to save space by placing labels behind text boxes (I know how to do this part) however it is the next part that I really need help with.

I attach an image with a test form showing what I currently get and what I would like.

I would like to be able to
1. see the label when the text box is empty
2. hide the label when the text box is not empty and I move to another field.

For information a number of my fields are fomatted as number and "0000" as per the image.

Many thanks in advance.

Eliz
 

Attachments

  • 2024 10 03 MS Access Form test.png
    2024 10 03 MS Access Form test.png
    14.9 KB · Views: 21
Instead of a label, I would say try to use a Textbox.
 
You could scrap the label completely and put prompt text in the textbox when it is empty (similar idea to that done on many websites).
 
Many thanks for your replies. I like the idea of scrapping the label and putting a prompt in the text box. will give this a try. How do you put a prompt in a textbox. Have found out how to do that using the @: in the format field however some of my fields are already using the formatting, eg, date or number .
 
Last edited:
Hi I don't know if what I want is possible but here goes.

I have a large form and would like to save space by placing labels behind text boxes (I know how to do this part) however it is the next part that I really need help with.

I attach an image with a test form showing what I currently get and what I would like.

I would like to be able to
1. see the label when the text box is empty
2. hide the label when the text box is not empty and I move to another field.

For information a number of my fields are fomatted as number and "0000" as per the image.

Many thanks in advance.

Eliz
i see what you're trying to do

Create a function to handle the visiblity. This is passing any TextBox into the function to get its value then retuning a True / False based on its contents

Function
Code:
Function SetVis(ByVal control As TextBox) As Boolean

'get the incoming textbox value
Dim val As String

'create an internal boolean to return
Dim res As Boolean: res = False

If IsNull(control.Value) Then
    val = ""
    res = True
Else
    val = control.Value
End If

'return the res
SetVis = res
End Function

In the forms OnLoad event, call the function like this
Code:
lblLabel.Visible = SetVis(txtText)

in the labels OnClick event, do this
Code:
lblLabel.Visible = False
txtText.SetFocus

in the Textbox Exit event, do this
Code:
lblLabel.Visible = SetVis(txtText)

The result on the form is this
1727969716719.gif
 
Thank you for this reply - I will take a look at this and give it a try.

I have tried this but am getting a runtime error 424 - object required on the textbox exit code


Private Sub rm_ref_no_Exit(Cancel As Integer)
lblLabel.Visible = SetVis(txtText)
End Sub

Have I done something wrong

thanks
 
Last edited:
Dim res As Boolean: res = False
I have to ask?, why the second statement?
When Booleans are first declared/dimmed, they are automatically False?
 
I have to ask?, why the second statement?
When Booleans are first declared/dimmed, they are automatically False?
its an assurance. I write in VB & C# now and by nature resolve every members declaration value

C#:
Dim name As String = String.Empty
Dim res As Boolean = False
C#:
string name = String.Empty;
bool res = false;
 

Users who are viewing this thread

Back
Top Bottom