Results 1 to 2 of 2
  1. #1
    lzook88 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    75

    Showing Mutliple Records in ONE textbox

    I am trying to loop through records and show them in a calendar. I want the records (Clinical Rotations) for each day to show in the box of the day.

    I currently am using this code and it shows only the first record.

    Code:
    Private Function DMonth1()
    Dim i As Integer
    Dim rs As DAO.Recordset
    Dim date1 As Integer
    
    date1 = Month(DateValue("01 " & Me.monthl & " " & Me.yearl))
    
    For i = 1 To 42
        If Me.Controls("D" & i).Visible Then
            Me.Controls("DA" & i) = ""
            Set rs = CurrentDb.OpenRecordset("SELECT tblClinical.[Clincial_ID], tblClinical.[Full_Name_FK], tblClinical.[Station_FK], tblClinical.[Agency_FK], tblClinical.[CDate] FROM tblClinical WHERE (((tblClinical.Agency_FK)=" & Me.Agency1.Column(0) & ") And ((tblClinical.CDate)=#" & Format(Me.Controls("D" & i), "MM/DD/YYYY") & "#));")
            If rs.EOF Then
            Else
            Me.Controls("DA" & i) = DLookup("FullName", "tblusers", "UserID=" & rs!Full_Name_FK)
            End If
        End If
    Next i
    
    End Function

    Idea:

    10/20/15 10/21/15
    Person1 Person8


    person2 Person5
    person3 Person6
    person4 Person7

    etc..

    and the PERSONS wld all be in the same textbox.

  2. #2
    lzook88 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    75
    and I figured it out by my self with just a little bit of working on it;

    this code is on the forum
    Code:
    Private Function DMonth1()
    Dim i As Integer
    Dim rs As DAO.Recordset
    Dim Date1 As Integer
    
    Date1 = Month(DateValue("01 " & Me.monthl & " " & Me.yearl))
    
    For i = 1 To 42
        If Me.Controls("D" & i).Visible Then
            Me.Controls("DA" & i) = ""
            Set rs = CurrentDb.OpenRecordset("SELECT tblClinical.Clincial_ID, tblUsers.FullName, tblClinical.Station_FK, tblClinical.CDate FROM tblUsers INNER JOIN tblClinical ON tblUsers.UserID = tblClinical.Full_Name_FK WHERE (((tblClinical.Agency_FK)=" & Me.Agency1.Column(0) & "));")
            If rs.EOF Then
            Else
            Me.Controls("DA" & i) = ConcatRelated("FullName", "qryClinical", "(((tblClinical.CDate)=#" & Format(Me.Controls("D" & i), "MM/DD/YYYY") & "#) AND ((tblClinical.Agency_FK)=" & Me.Agency1 & "))", , vbNewLine)
            End If
        End If
    Next i
    
    End Function

    and this code is a function in a separate module
    Code:
    Public Function ConcatRelated(strField As String, _
        strTable As String, _
        Optional strWhere As String, _
        Optional strOrderBy As String, _
        Optional strSeparator = ", ") As Variant
    On Error GoTo Err_Handler
        'Purpose:   Generate a concatenated string of related records.
        'Return:    String variant, or Null if no matches.
        'Arguments: strField = name of field to get results from and concatenate.
        '           strTable = name of a table or query.
        '           strWhere = WHERE clause to choose the right values.
        '           strOrderBy = ORDER BY clause, for sorting the values.
        '           strSeparator = characters to use between the concatenated values.
        'Notes:     1. Use square brackets around field/table names with spaces or odd characters.
        '           2. strField can be a Multi-valued field (A2007 and later), but strOrderBy cannot.
        '           3. Nulls are omitted, zero-length strings (ZLSs) are returned as ZLSs.
        '           4. Returning more than 255 characters to a recordset triggers this Access bug:
        '               http://allenbrowne.com/bug-16.html
        Dim rs As DAO.Recordset         'Related records
        Dim rsMV As DAO.Recordset       'Multi-valued field recordset
        Dim strSql As String            'SQL statement
        Dim strOut As String            'Output string to concatenate to.
        Dim lngLen As Long              'Length of string.
        Dim bIsMultiValue As Boolean    'Flag if strField is a multi-valued field.
        
        'Initialize to Null
        ConcatRelated = Null
        
        'Build SQL string, and get the records.
        strSql = "SELECT " & strField & " FROM " & strTable
        If strWhere <> vbNullString Then
            strSql = strSql & " WHERE " & strWhere
        End If
        If strOrderBy <> vbNullString Then
            strSql = strSql & " ORDER BY " & strOrderBy
        End If
        Set rs = DBEngine(0)(0).OpenRecordset(strSql, dbOpenDynaset)
        'Determine if the requested field is multi-valued (Type is above 100.)
        bIsMultiValue = (rs(0).Type > 100)
        
        'Loop through the matching records
        Do While Not rs.EOF
            If bIsMultiValue Then
                'For multi-valued field, loop through the values
                Set rsMV = rs(0).Value
                Do While Not rsMV.EOF
                    If Not IsNull(rsMV(0)) Then
                        strOut = strOut & rsMV(0) & strSeparator
                    End If
                    rsMV.MoveNext
                Loop
                Set rsMV = Nothing
            ElseIf Not IsNull(rs(0)) Then
                strOut = strOut & rs(0) & strSeparator
            End If
            rs.MoveNext
        Loop
        rs.Close
        
        'Return the string without the trailing separator.
        lngLen = Len(strOut) - Len(strSeparator)
        If lngLen > 0 Then
            ConcatRelated = Left(strOut, lngLen)
        End If
    
    Exit_Handler:
        'Clean up
        Set rsMV = Nothing
        Set rs = Nothing
        Exit Function
    
    Err_Handler:
        MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation, "ConcatRelated()"
        Resume Exit_Handler
    End Function
    :-)

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

Similar Threads

  1. Form with mutliple record source (s0
    By Lou_Reed in forum Access
    Replies: 6
    Last Post: 05-12-2015, 03:13 PM
  2. Replies: 5
    Last Post: 03-14-2015, 11:44 PM
  3. Replies: 3
    Last Post: 10-15-2013, 10:54 AM
  4. Creating a query using mutliple tables
    By andrewmo in forum Queries
    Replies: 1
    Last Post: 11-21-2011, 01:11 PM
  5. Replies: 5
    Last Post: 10-27-2011, 10:25 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