Results 1 to 6 of 6
  1. #1
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496

    msg box is truncating (!?)


    i've got this simple code behind a command button, in debug.print I get complete data, but when I assign that data to a msgbox... it truncates to the first record only
    Does anyone see something that I'm not seeing ?

    (with thanks in advance,m.)

    Code:
    Sub ShowUserRosterMultipleUsers()
    Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim i, j As Long
    strtext = ""
    Set cn = CurrentProject.Connection
    
    Dim dbs As Database, tbl As TableDef, fld
    Set dbs = CurrentDb
    
    Set tbl = dbs.CreateTableDef("Users")
    Set fld = tbl.CreateField("User", dbText)
    
    ' The user roster is exposed as a provider-specific schema rowset
    ' in the Jet 4.0 OLE DB provider.  You have to use a GUID to
    ' reference the schema, as provider-specific schemas are not
    ' listed in ADO's type library for schema rowsets
    
    Set rs = cn.OpenSchema(adSchemaProviderSpecific, _
    , "{947bb102-5d43-11d1-bdbf-00c04fb92675}")
    
    'Output the list of all users in the current database.
    
    'Debug.Print rs.Fields(0).Name, "", rs.Fields(1).Name, _
    "", rs.Fields(2).Name, rs.Fields(3).Name
    
    While Not rs.EOF
        Debug.Print rs.Fields(0), rs.Fields(1), _
        rs.Fields(2), rs.Fields(3)
        strtext = Trim(strtext) _
                & ", " & rs.Fields(0)
        rs.MoveNext
        
    Wend
    strtext = IIf(Len(Nz(strtext, "")) = 0, "no other users connected", strtext)
    Response = MsgBox(strtext, vbOKOnly + vbInformation, "Current Connections to MDb")
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,919
    Cannot replicate issue and don't see anything wrong with code. However, I have never used OpenSchema. It's not even showing in intellisense tip. I would use OpenRecordset.

    Could simplify the MsgBox code and don't need the Response variable:

    MsgBox strtext, vbInformation, "Current Connections to MDB"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,411
    Does anyone see something that I'm not seeing ?
    Looks like strtext is concatenating rs.fields(0) only, over and over.

    It also appears you are not using option explicit, as 'response' is not dimmed but is not causing an error.
    Last edited by davegri; 12-27-2018 at 04:10 PM. Reason: more

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,919
    @davegri, code is concatentating Field(0) of multiple records because of rs.MoveNext. This works perfect for me. There is a comma at beginning of the displayed string but the code does work. I have to use OpenRecordset instead of OpenSchema.

    Variable strtext is also not declared.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,411
    @davegri, code is concatentating Field(0) of multiple records because of rs.MoveNext.
    Yes, I understood that. The OP's complaint was that the debug.print was different from the message box, showing only one record. The debug.print is showing 4 fields, the message box just one, which is quite different.
    Perhaps OP can provide more complete description of the problem...

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,919
    Right, should "truncates to the first record only" have stated "truncates to the first field only"? Should the MsgBox string include all 4 fields or just Fields(0)?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Recordset truncating after 255 character
    By selvakumar.arc in forum Macros
    Replies: 1
    Last Post: 01-15-2015, 03:37 PM
  2. Concatenating in Query and Truncating Export
    By electromarket in forum Queries
    Replies: 7
    Last Post: 07-03-2013, 07:30 AM
  3. Truncating SQL Server table from Access
    By lbrady in forum Import/Export Data
    Replies: 3
    Last Post: 03-01-2013, 04:46 AM
  4. Query is Truncating Memo Field
    By Huddle in forum Queries
    Replies: 1
    Last Post: 07-24-2012, 02:24 PM
  5. Subreport Truncating in 2010
    By rdavid in forum Reports
    Replies: 2
    Last Post: 12-13-2011, 09:08 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