I have the following working. The code between the *** is what I am looking to change. I would prefer writing the result of the SQL directly to my userform spreadsheet control rather than sending it to a worksheet then pasting it to the spreadsheet control.
Any help would be appreciated.
Thanks,
Kurt
Public Sub PopulateSpreadsheet()
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim MySQLcheck As String
Dim intFieldCount, i As Integer
Set cnn = New ADODB.Connection
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=S:\Sunkist\Sunkist.mdb"
MySQLcheck = "select * from XXXFG_Leadtime where WH_From = '" & UF_WorkOrder.MultiPage1(1).oCB1.Value & "';"
Set rst = cnn.Execute(MySQLcheck)
intFieldCount = rst.Fields.Count
rst.MoveFirst
'*****************************************************
Sheet1.Cells.ClearContents
For i = 0 To intFieldCount - 1
With Sheet1.Range("A1").Offset(0, i)
.Value = rst.Fields(i).Name
End With
Next
'*****************************************************
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
End Sub