Hi guys
I want to display query result from access table in Excel sheet. In this project the backend is Access and the frontend is excel. But the sheet 3 doesn't display any value.
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim r As Long
' connect to the Access database
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=C:\Documents and Settings\Amanpreet Kaur\Desktop\resc.mdb;"
' open a recordset
Set rs = New ADODB.Recordset
rs.Open "tblmain", cn, adOpenKeyset, adLockOptimistic, adCmdTable
rs.Find "Department = ' " & ComboBox1.Value & " '
Dim oApp As Excel.Application
Set oApp = CreateObject("Excel.Application")
Set ows = ThisWorkbook.Worksheets("sheet3")
Do While Not rs.EOF
Dim y As Long, x As Long
y = 1
For x = 1 To rs.Fields.Count
ows.Cells(y, x) = rs.Fields(x)
Next
y = y + 1
rs.MoveNext
Loop
ows.PrintOut
End Sub
Can anyone please solve my problem.
Regards
Aman
Bookmarks