Results 1 to 6 of 6
  1. #1
    SMC's Avatar
    SMC is offline Master Ninja
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Columbus, OH
    Posts
    28

    Text box Autofilling from 3 list box values.

    Hello,

    Description:

    1 Text Box (bound)
    3 List Boxes (unbound)

    User will choose values for the 3 List Boxes.
    List Box 1: Values 1-9
    List Box 2: Values 1-9
    List box 3: Values A-Z



    Now, The Text Box needs to populate in such manner: "LB1""LB2"_"LB3"
    I want to produce a 2 digit code, "space", then the LB3 value. ex; '12_A'

    The Text Box value will then be saved into my records.

    The values in this thread's example scenario have been simplified to focus on a method of achieving it.

    I would like the Text Box to populate as I choose the value of List Box 3.

    Thanks,

    SMC

  2. #2
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You would use this expression as the control source for the text box

    =[LB1] & [LB2] & "_" & [LB3]

    Now, since what is shown in the textbox is essentially a calculated value and in general, calculated values should not be stored; it is the list boxes that should be bound (each to a field) and the text box should be unbound. When you need to show the calculated value, you would just calculate it on the fly in queries, forms and reports.

  3. #3
    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
    I have to disagree with you! While storing Calculated Fields is usually, quite rightfully, frowned upon, I think this case is one of the acceptable reasons! These three Listboxes have no intrinsic value, here, and are only being used to facilitate data entry. Storing three such Fields instead of a single Field just seems wasteful and unnecessary, to me.

    I would, however, take into account the possibility that the users may not select from the Listboxes in the order the developer expects, and do something like this:

    Code:
    Private Sub LB1_AfterUpdate()
     Call ConCatFields
    End Sub
    
    Private Sub LB3_AfterUpdate()
     Call ConCatFields
    End Sub
    
    Private Sub LB2_AfterUpdate()
     Call ConCatFields
    End Sub
    
    Private Sub ConCatFields()
     If Nz(Me.LB1, "") <> "" And Nz(Me.LB2, "") <> "" And Nz(Me.LB3, "") <> "" Then
      Me.TargetTextBox = Me.LB1 & Me.LB2 & "_" & Me.LB3
     End If
    End Sub


    Also, not using the Control Source to do this will allow the user, if a mistake is made, such as selecting 'C' when they meant to select 'D,' to quickly edit the TargetTextBox to reflect this.

    Just my opinion; to each his own!

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

    All posts/responses based on Access 2003/2007

  4. #4
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    Missinglinq,

    I see your point, perhaps I was reading into the post a little too much. I interpreted the list boxes of the post as a generic representations of 3 terms that actually have some meaning. I was working on another post where the poster was storing the individual terms as well as the concatenated value.

  5. #5
    SMC's Avatar
    SMC is offline Master Ninja
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Columbus, OH
    Posts
    28
    Thanks guys. Very helpful.

    Missinglinq, another problem you have helped me with!

  6. #6
    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
    Quote Originally Posted by jzwp11 View Post
    ...I was working on another post where the poster was storing the individual terms as well as the concatenated value.
    Well, everything else aside, it is definitely a 'save either/or' situation, but not a 'save both' one!

    SMC: Glad we could, once again, 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. Combo Box - Field List Values
    By jennyaccord in forum Forms
    Replies: 5
    Last Post: 07-29-2011, 01:49 PM
  2. ID field autofilling text field on another form
    By ledmark in forum Programming
    Replies: 0
    Last Post: 03-24-2011, 10:12 PM
  3. Help autofilling a field
    By fullause in forum Access
    Replies: 1
    Last Post: 02-18-2011, 05:54 AM
  4. List all values in one cell?
    By Remster in forum Queries
    Replies: 5
    Last Post: 12-17-2010, 04:33 AM
  5. Filter available values in a drop down list
    By petitmorsalin in forum Access
    Replies: 1
    Last Post: 12-13-2010, 09:39 AM

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