Imports System.Data.SqlClient

Module modFunction
    Public Function GetFieldValue(ByVal srcSQL As String, ByVal strField As String)
        'create connection
        Dim conn As New SqlConnection(My.Settings.LibSysConnectionString)

        With conn
            If .State = ConnectionState.Open Then .Close()

            .Open()
        End With

        Try
            Dim cmd As SqlCommand = New SqlCommand(srcSQL, conn)
            'create data reader
            Dim rdr As SqlDataReader = cmd.ExecuteReader

            'loop through result set
            While (rdr.Read)
                GetFieldValue = rdr(strField).ToString()
            End While

            'close data reader
            rdr.Close()
        Catch ex As SqlException
            MsgBox(ex.Message)
        Finally
            ' Close connection
            conn.Close()
        End Try
    End Function
End Module
