|
-
Jun 3rd, 2003, 03:58 PM
#1
Thread Starter
New Member
Help with VBA SQL Statements
Hi...
I'm writing some code that takes data out of Access and puts it inot Excel to plot a graph using SQL statements. It works fine, but if I use 'WHERE' in my SQL statement, it does not show anything. Otherwise it works just fine. As a result, I have TOO many values toi plot. I need to use 'WHERE' in the SQL statement to reduce the number of records that are pulled out of Access and put intot Excel.
Can someone help me with this problem?
kaspar
-
Jun 3rd, 2003, 03:59 PM
#2
Frenzied Member
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Jun 5th, 2003, 04:48 AM
#3
Lively Member
Here's the code [edited by alex_read - 05/06/2003]
VB Code:
Private Sub CommandButton3_Click()
Dim cnn As ADODB.Connection
Dim rsTemp As ADODB.Recordset
Dim cmdCommand As ADODB.Command
Dim i As Integer
i = 2
' Open the connection.
Set cnn = New ADODB.Connection
With cnn
.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0"
.Open ThisWorkbook.Path & "\x.mdb"
End With
' Set the command text.
Set cmdCommand = New ADODB.Command
Set cmdCommand.ActiveConnection = cnn
With cmdCommand
.CommandText = "SELECT [Trapping Information].Week, [Mouse-Main].Chip " & _
"FROM [Mouse-Main] INNER JOIN [Trapping Information] " & _
"ON [Mouse-Main].ID = [Trapping Information].[Mouse-Main_ID] " & _
"WHERE ((([Mouse-Main].Chip)=201-87E3));"
.CommandType = adCmdText
.Execute
End With
' Open the recordset.
Set rsTemp = New ADODB.Recordset
Set rsTemp.ActiveConnection = cnn
rsTemp.Open cmdCommand
'Move to start of recordset if not there already
If Not rsTemp.BOF Then rsTemp.MoveFirst
Do While Not rsTemp.EOF
Cells(i, 1).Value = rsTemp("Chip")
Cells(i, 2).Value = rsTemp("Week")
i = i + 1
rsTemp.MoveNext
Loop
Set cmdCommand = Nothing
rsTemp.Close
cnn.Close
End Sub
Last edited by alex_read; Jun 5th, 2003 at 05:43 AM.
-
Jun 5th, 2003, 05:38 AM
#4
What if you used a like clause & not an equal to, does his show anything...
WHERE ((([Mouse-Main].Chip) LIKE 201%
(not sure if that's percentage or * there, one works with access & not SQL server & visa versa.
Also, are you searching a string column & need to enclost the figure in single quotes?
-
Jun 5th, 2003, 05:47 AM
#5
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|