Results 1 to 7 of 7
  1. #1
    tatihulot is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    60

    How Do I Get a Main Form's Text Box to Continually Display the Same Text Until I Change It?

    Hello, I am using Access 2013, and consider myself a novice database designer. Hopefully this is a simple question to answer.



    I have a one-to-many relational database, with a main form and a subform. In the main form is a text box named ARTIST.

    What I'd like to do is have the text in that text box repeat itself in every new record, until or unless I manually enter different data in it.

    Then, when I enter the different data, I'd like THAT data to repeat itself, until or unless I change it manually again.

    Is there a relatively easy way to accomplish this? If so, what is the procedure? If you need further information from me, please let me know. Thank you. T. Hulot

  2. #2
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    You can use the AfterUpdate event of the Control holding your data to set the DefaultValue for the Field. From that time forward, until you either manually change the data or close your form, the data will be entered automatically in each New Record.

    Code:
    Private Sub YourControlName_AfterUpdate()
       Me.YourControlName.DefaultValue = """" & Me.YourControlName.Value & """"
    End Sub

    This syntax is valid for Text, Number, DateTime and Boolean Datatypes.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    tatihulot is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    60
    Thank you.

    One thing about your code I do not understand.

    Me.YourControlName.DefaultValue = """" & Me.YourControlName.Value & """"
    I do understand I substitute the actual control name for YourControlName.
    What I don't understand is whether or not to put the remaining code in as is, or substitute the two instances of quotation marks """ with something else.

  4. #4
    tatihulot is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    60
    Okay, I tried it as is, just substituting the control name, and it seems to be working. Thank you! I'll reply back if I hit any snags.

    But I really would like to understand what the three quotation marks represent. Would you be willing to elaborate? Thanks again.

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Different DataTypes require different delimiters; Text requires Quotes, DateTime requires Octothorp (hash mark/pound sign or #) and numbers require none.

    Using this type of code originally required using these delimiters, depending on the Datatype involved, so for a DateTime Field you'd use

    Me.YourControlName.DefaultValue = # & Me.YourControlName.Value & #

    and for a Numbers Field

    Me.YourControlName.DefaultValue = Me.YourControlName.Value

    and so forth. Then someone (no idea who...it's been so long ago) realized that using the quadruple set of Double-Quotes allows one exact line of code

    Me.YourControlName.DefaultValue = """" & Me.YourControlName.Value & """"

    to be used, regardless of the Datatype!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  6. #6
    tatihulot is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    60
    Works perfectly. Thank you for your assistance.

  7. #7
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Glad we could help!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 10-03-2014, 10:07 AM
  2. Replies: 19
    Last Post: 06-30-2014, 04:36 PM
  3. Replies: 1
    Last Post: 06-18-2014, 09:39 PM
  4. Replies: 9
    Last Post: 04-18-2014, 08:51 PM
  5. Change the text box color on form load
    By mikec in forum Programming
    Replies: 2
    Last Post: 03-01-2010, 11:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums