Option Compare Database
Option Explicit

' ============================================================
' : mQueryHelpers
'
' :
'      .
' ============================================================


Public Function GetBrewNumbersForFermentation(ByVal fermentationNumber As Variant) As String

    '       .
    '
    ' :
    '   t
    '
    '  :
    '   1; 2; 3
    '
    '      ,
    '        [ ].

    On Error GoTo ErrorHandler

    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim SqlText As String
    Dim resultText As String

    resultText = ""

    If IsNull(fermentationNumber) Then
        GetBrewNumbersForFermentation = ""
        Exit Function
    End If

    If Nz(fermentationNumber, 0) = 0 Then
        GetBrewNumbersForFermentation = ""
        Exit Function
    End If

    Set db = CurrentDb

    SqlText = _
        "SELECT DISTINCT [ ] " & _
        "FROM [t] " & _
        "WHERE [ ] = " & CLng(fermentationNumber) & " " & _
        "AND Nz([], False) = False " & _
        "AND [ ] Is Not Null " & _
        "ORDER BY [ ];"

    Set rs = db.OpenRecordset(SqlText, dbOpenSnapshot)

    Do While Not rs.EOF

        If resultText <> "" Then
            resultText = resultText & "; "
        End If

        resultText = resultText & CStr(rs.Fields(" ").value)

        rs.MoveNext

    Loop

    GetBrewNumbersForFermentation = resultText

ExitPoint:

    On Error Resume Next

    If Not rs Is Nothing Then
        rs.Close
    End If

    Set rs = Nothing
    Set db = Nothing

    Exit Function

ErrorHandler:

    GetBrewNumbersForFermentation = ""

    Resume ExitPoint

End Function