amypaulsen
Board Regular
- Joined
- Mar 1, 2004
- Messages
- 114
I am trying to pull access into excel using SQL while referencing a cell within my spreadsheet to reference. below is the code that I am using...and while it looks like something is happening...nada
can you help?
Private Sub cmdRun_Click()
Dim objAccess As Object
Dim objDB As Object
Dim rst As Object
Dim strSQL As String
Sheets("Current Week").Select
Set objAccess = CreateObject("access.application")
With objAccess
.opencurrentdatabase (ActiveWorkbook.Path & "\Flash FY05.mdb")
BeginLoop:
Set objDB = objAccess.currentdb()
With objDB
strSQL = "SELECT tblTransactions.UNIT, tblTransactions.W51 from [tblTransactions] where tblTransactions.UNIT = '" & Cells(12, 35).Value & "'"
Set rst = objDB.openrecordset(strSQL)
If Not rst.RecordCount = 0 Then
rst.movefirst
Do
colnum = 32
rownum = 20
Sheets("current week").Select
If Cells(12, colnum).Value = rst.fields("UNIT").Value Then
For Each fld In rst.fields
colnum = colnum + 1
Cells(rownum, colnum).Value = rst.fields("W51").Value
Next fld
End If
rst.movenext
Loop Until rst.EOF
End If
End With
End With
rst.Close
End Sub
can you help?
Private Sub cmdRun_Click()
Dim objAccess As Object
Dim objDB As Object
Dim rst As Object
Dim strSQL As String
Sheets("Current Week").Select
Set objAccess = CreateObject("access.application")
With objAccess
.opencurrentdatabase (ActiveWorkbook.Path & "\Flash FY05.mdb")
BeginLoop:
Set objDB = objAccess.currentdb()
With objDB
strSQL = "SELECT tblTransactions.UNIT, tblTransactions.W51 from [tblTransactions] where tblTransactions.UNIT = '" & Cells(12, 35).Value & "'"
Set rst = objDB.openrecordset(strSQL)
If Not rst.RecordCount = 0 Then
rst.movefirst
Do
colnum = 32
rownum = 20
Sheets("current week").Select
If Cells(12, colnum).Value = rst.fields("UNIT").Value Then
For Each fld In rst.fields
colnum = colnum + 1
Cells(rownum, colnum).Value = rst.fields("W51").Value
Next fld
End If
rst.movenext
Loop Until rst.EOF
End If
End With
End With
rst.Close
End Sub