E
Eric
OK..maybe I am asking the wrong question latelty or not
explaining myself quite right.
How do you gurus get the records from a Access database
put into Excel? I know that you can do it through
automation, but here is my situation.
I have a Excel spreadsheet where users have a dropdown
list and they can select a plant. In our master Access
database, we have product lines associated to a plant in a
query called qryPlantProductLine. When the user selects a
Plant, it should call the query and display the results in
a sheet which the following code runs:
***********************************************
Sub PlantProductLines()
Dim DBFullName As String
Dim Cnct As String, Src As String
Dim Connection As ADODB.Connection
Dim Recordset As ADODB.Recordset
Dim Col As Integer
Dim Row As Integer
Dim strPlantName As String
'Database Information
DBFullName = "J:\QA\QAMaster\QAMaster.mdb"
'Open the connection
Set Connection = New ADODB.Connection
Cnct = "Provider=Microsoft.Jet.OLEDB.4.0; "
Cnct = Cnct & "Data Source=" & DBFullName & ";"
Connection.Open ConnectionString:=Cnct
'Create RecordSet
strPlantName = ActiveSheet.Range("L4").Value '
Set Recordset = New ADODB.Recordset
With Recordset
'Filter
Src = "SELECT qryPlantProductLine.PlantName,
qryPlantProductLine.LineCode, qryPlantProductLine.LineName
FROM `J:\QA\QAMaster\QAMaster`.qryPlantProductLine
qryPlantProductLine WHERE
(qryPlantProductLine.PlantName='Leola')" 'for test puropses
.Open Source:=Src, ActiveConnection:=Connection
*******************************************************
Here's where I am having problems (the rest of the code):
********************************************************
Debug.Print Recordset.MaxRecords ' I get zero here!!!
'Write the field names (which come in)
For Col = 0 To Recordset.Fields.Count - 1
Range("P12").Offset(0, Col).Value =
Recordset.Fields(Col).Name
Next
MsgBox Recordset.RecordCount 'get zero here too!
End With
Set Recordset = Nothing
Connection.Close
Set Connection = Nothing
End Sub
***********************************************
When I go to the Debug.Print .MaxRecords and look in the
Immediate Window, I get zero records returned. If I plug
the SQL statement in ANY Access database, I get results
for the query (they are correct).
Why can't I get any results from my query in Excel if I
get results in a Access query? Am I doing something
wrong???
explaining myself quite right.
How do you gurus get the records from a Access database
put into Excel? I know that you can do it through
automation, but here is my situation.
I have a Excel spreadsheet where users have a dropdown
list and they can select a plant. In our master Access
database, we have product lines associated to a plant in a
query called qryPlantProductLine. When the user selects a
Plant, it should call the query and display the results in
a sheet which the following code runs:
***********************************************
Sub PlantProductLines()
Dim DBFullName As String
Dim Cnct As String, Src As String
Dim Connection As ADODB.Connection
Dim Recordset As ADODB.Recordset
Dim Col As Integer
Dim Row As Integer
Dim strPlantName As String
'Database Information
DBFullName = "J:\QA\QAMaster\QAMaster.mdb"
'Open the connection
Set Connection = New ADODB.Connection
Cnct = "Provider=Microsoft.Jet.OLEDB.4.0; "
Cnct = Cnct & "Data Source=" & DBFullName & ";"
Connection.Open ConnectionString:=Cnct
'Create RecordSet
strPlantName = ActiveSheet.Range("L4").Value '
Set Recordset = New ADODB.Recordset
With Recordset
'Filter
Src = "SELECT qryPlantProductLine.PlantName,
qryPlantProductLine.LineCode, qryPlantProductLine.LineName
FROM `J:\QA\QAMaster\QAMaster`.qryPlantProductLine
qryPlantProductLine WHERE
(qryPlantProductLine.PlantName='Leola')" 'for test puropses
.Open Source:=Src, ActiveConnection:=Connection
*******************************************************
Here's where I am having problems (the rest of the code):
********************************************************
Debug.Print Recordset.MaxRecords ' I get zero here!!!
'Write the field names (which come in)
For Col = 0 To Recordset.Fields.Count - 1
Range("P12").Offset(0, Col).Value =
Recordset.Fields(Col).Name
Next
MsgBox Recordset.RecordCount 'get zero here too!
End With
Set Recordset = Nothing
Connection.Close
Set Connection = Nothing
End Sub
***********************************************
When I go to the Debug.Print .MaxRecords and look in the
Immediate Window, I get zero records returned. If I plug
the SQL statement in ANY Access database, I get results
for the query (they are correct).
Why can't I get any results from my query in Excel if I
get results in a Access query? Am I doing something
wrong???