Solved Default Information in a TextBox with the ability to add more MainForm (1 Viewer)

Local time
Today, 06:05
Joined
Jun 3, 2022
Messages
38
Hello! Need some help regarding a TextBox within a form that needs to be populated already whenever a user enters the form and can add additional information within the text box.

For example, a TextBox in the MainForm must have "ABCDEF" inside of it by Default and can't be removed/backspaced out.
But the user can continue to add more numbers to it "ABCDEF-123" and save it to the subform.

I am not sure if this is possible within the property sheet or VBA code. Thanks for any ideas, feedback, or suggestions!
 

Attachments

  • textboximage.png
    textboximage.png
    1.3 KB · Views: 86

Mike Krailo

Well-known member
Local time
Today, 07:05
Joined
Mar 28, 2020
Messages
1,030
Just have that text box locked so no changes can be made and have another bound field on the form for adding the additional text to be concatenated. So essentially, editable part is simply stored in another field.

Then concatenate the two fields as needed wherever needed on a report or form.
 

KitaYama

Well-known member
Local time
Today, 20:05
Joined
Jan 6, 2022
Messages
1,490
Set the default value of the text box to "ABCDEF" and on got focus event would be

Code:
Private Sub MyTextBox_GotFocus()

    MyTextBox.SelStart = Len(MyTextBox)
  
End Sub
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:05
Joined
May 7, 2009
Messages
19,175
the Default Value of the "theText" textbox is "ABCDEF".
there is a code in the Change event of this textbox.
 

Attachments

  • ABCDEF.accdb
    440 KB · Views: 115

Mike Krailo

Well-known member
Local time
Today, 07:05
Joined
Mar 28, 2020
Messages
1,030
Very creative arnel. I had to step through that one to see what was going on. I have an existing application that this would work great in. I didn't really need the ability to prevent the user from erasing the default value in my app but it's nice to know that this can be done. It's going into the bag of tricks immediately.

One thing though. What is the purpose of def = Replace$(.DefaultValue, Chr(34), "") as it seems like it just replaces a double quote with a double quote??? Never mind, I see now that it prevents the user from inserting a space into the default value part of the string. Very nice, unless the user needs to append some text that has a space in it. In that case, the newly inserted text will get erased. Not likely though.
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:05
Joined
May 7, 2009
Messages
19,175
Default Value has "double Quote" on it, like:

Me.txtbox.DefaultValue = """theDefaultValueHere"""

therefore, i remove them first before using in th expression.
 

Mike Krailo

Well-known member
Local time
Today, 07:05
Joined
Mar 28, 2020
Messages
1,030
Ah, I see now. Thanks for the explanation Arnel.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 07:05
Joined
Feb 19, 2002
Messages
42,981
Maybe if you used the real string this requirement would make sense. But a literal is a literal and does not need to be stored.
 
Local time
Today, 06:05
Joined
Jun 3, 2022
Messages
38
the Default Value of the "theText" textbox is "ABCDEF".
there is a code in the Change event of this textbox.
Just what I wanted! I just used ABCDEF as an example for the default information in a text, but the code worked!
 
Local time
Today, 06:05
Joined
Jun 3, 2022
Messages
38
Very creative arnel. I had to step through that one to see what was going on. I have an existing application that this would work great in. I didn't really need the ability to prevent the user from erasing the default value in my app but it's nice to know that this can be done. It's going into the bag of tricks immediately.

One thing though. What is the purpose of def = Replace$(.DefaultValue, Chr(34), "") as it seems like it just replaces a double quote with a double quote??? Never mind, I see now that it prevents the user from inserting a space into the default value part of the string. Very nice, unless the user needs to append some text that has a space in it. In that case, the newly inserted text will get erased. Not likely though.
Yes, I was looking for this all over the internet on how to create the action but as always the Forum comes in handy.
 
Local time
Today, 06:05
Joined
Jun 3, 2022
Messages
38
Just have that text box locked so no changes can be made and have another bound field on the form for adding the additional text to be concatenated. So essentially, editable part is simply stored in another field.

Then concatenate the two fields as needed wherever needed on a report or form.
I wanted to comeback and thank you for posting this because I needed a TextBox (Year) to be defaulted as "2023" and no deletions or additions can be made within the text field so I "Locked It" and it works perfectly fine. The one above I needed a Default value to be in there but a user can add information after the value or can't backspace or remove it. (Arnel with the save on that one!)
 

Users who are viewing this thread

Top Bottom