Results 1 to 10 of 10
  1. #1
    runthis457 is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Feb 2011
    Posts
    16

    Append to TextBox Not OverWrite


    I am using ADO to cycle through data in a table. I want to be able to display in a textbox on a form each record that the textbox cycled through. My problem is that each subsequent record that is cycled overwrites the value that is already there, so the result I get is only the final record that is touched. How would you set VBA to show all?

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Not knowing your code or what look you're going for, this would be one way:

    Me.TextboxName = Me.TextboxName & rs!FieldName & "; "

    Trim off the trailing "; " after the loop if you wish.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    runthis457 is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Feb 2011
    Posts
    16
    Code:
    Dim conn As ADODB.Connection
    Dim rst As ADODB.Recordset
    Dim strSQL As String
    Set conn = CurrentProject.Connection
    
    Set rst = New ADODB.Recordset
    
    strSQL = "Select fileName from tblTest"
    
    rst.Open strSQL, conn
    
    Do Until rst.EOF
    Debug.Print rst("fileName")
    
    placeHolder = Forms![Form1]![Slave].Value
    MsgBox rst("fileName")
    Forms![Form1]![Master].Value = Replace(placeHolder, "_Main", rst("fileName"))
    
    rst.MoveNext
    Loop
    
    rst.Close
    Set rst = Nothing
    conn.Close
    Set conn = Nothing
    End Sub
    And I want
    Code:
    placeHolder = Forms![Form1]![Slave].Value
    MsgBox rst("fileName")
    Forms![Form1]![Master].Value = Replace(placeHolder, "_Main", rst("fileName"))
    To show each fileName in the textbox Master on my form, not overwrite.

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Did you try my suggested method (replacing with your specifics of course)?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    runthis457 is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Feb 2011
    Posts
    16
    I didn't really follow what you were suggesting, thought it might be easier to post my code and let you say definitively.

  6. #6
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    My suggestion was to concatenate the existing contents of the textbox with the new value. I added a semi-colon to separate them, but you can use anything including a carriage return (vbCrLf in VBA). In other words,

    Target = Target & NewValue & Delimiter
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    runthis457 is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Feb 2011
    Posts
    16
    So if I am following you it would read like this:
    Code:
    Master = Master & NewValue & vbCrLf

  8. #8
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Forms![Form1]![Master].Value = Forms![Form1]![Master].Value & Replace(placeHolder, "_Main", rst("fileName")) & "; "
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    runthis457 is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Feb 2011
    Posts
    16
    Works Perfect!!! Thank you!

  10. #10
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Autopopulate NOT allowing overwrite
    By ChrisCione in forum Forms
    Replies: 8
    Last Post: 09-03-2010, 06:29 PM
  2. Update not overwrite
    By dada in forum Programming
    Replies: 8
    Last Post: 08-19-2010, 06:21 PM
  3. Overwrite existing tables
    By magua in forum Import/Export Data
    Replies: 1
    Last Post: 06-21-2010, 11:32 AM
  4. Table Overwrite
    By ml2009 in forum Access
    Replies: 3
    Last Post: 01-14-2010, 07:06 AM
  5. Import and overwrite?
    By Ben in forum Import/Export Data
    Replies: 3
    Last Post: 08-11-2009, 08:43 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