I am not sure if this is what you are looking for but here goes.
Private arr(4) As String
Private rsData As New ADODB.Recordset
Private hDB As New ADODB.Connection
Private Sub Form_Initialize()
arr(0) = "Field1"
arr(1) = "Field2"
arr(2) = "Field3"
arr(3) = "Field4"
arr(4) = "Field5"
End Sub
Private Function BuildSQL(ByVal Mode As Long) As String
Dim iX As Long
Dim sSQL As String
sSQL = "Select "
For iX = 0 To Mode
sSQL = sSQL & arr(iX) & ", "
Next
sSQL = sSQL & "From myTable"
BuildSQL = sSQL
End Function
Private Function ConnectDB() As Boolean
Dim sTmp As String
sTmp = "C:/myDB.mdb"
On Error GoTo ErrHnd
hDB.ConnectionString = sTmp
hDB.Mode = adModeReadWrite
hDB.Open
If rsData.State = adStateOpen Then
rsData.Close
End If
sTmp = BuildSQL(4)
With rsData
.ActiveConnection = hDB
.CursorLocation = adUseServer
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open sTmp
End With
rsData.Close
ConnectDB = True
Exit Function
ErrHnd:
MsgBox Err.Number & " " & Err.Description & " Error Generated By " & Err.Source, vbCritical, "System Error Trap !"
ConnectDB = False
End Function
Hope this helps
Anything is possible, the problem is I only have one lifetime.
![[cheers] [cheers] [cheers]](/data/assets/smilies/cheers.gif)