LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default problem with importing data from access to excel

dear excel guru,
I have been trying to import data from acces to excel, but I can not do
it in a way I want it..Below is the code (sorry it is al little messy).
There are many extraneous codes. AS is now, it gives me either eof or
bof error. If I comment out WHERE clause in sqlstr, it retrieves
everything fine except with some odd date values that I can't see in
the original table.. So, I can't get rid of those odd dae values and it
keeps giving me script out of range error.. Also the reason why I
importing this way is that I have to copy the data on a worksheet where
I have the leave a blank column between retrieved columns..please
help..
Dim REPDATE As String
Private Sub CommandButton1_Click()

Call ADOImportFromAccessTabLE("SIBOR_V8.MDB", "ALLOCATIONquery",
REPDATE, Range("b1"))

End Sub

Sub ADOImportFromAccessTabLE(DBFullName As String, TableName As String,
FieldName As String, TargetRange As Range)
Dim cn As ADODB.Connection, rs As ADODB.Recordset, intColIndex As
Integer
Dim SQLSTR As String
Set TargetRange = TargetRange.Cells(2, 2)
' open the database
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
DBFullName & ";"
Set rs = New ADODB.Recordset
REPDATE = InputBox("ENTER MONTH AND YEAR-Eg:02-04", "INPUT")
MsgBox (REPDATE)
SQLSTR = "SELECT * FROM allocation WHERE ALLOCATION.DATE=" &
REPDATE & ";"
rs.Open SQLSTR, cn, , adLockPessimistic 'adOpenDynamic,
adLockPessimistic
Dim VARARRAY As Variant
VARARRAY = rs.GetRows()
With rs
' open the recordset
' .Open TableName, cn, adOpenStatic, adLockOptimistic,
adCmdTable


III = UBound(VARARRAY, 2) + 1
JJJ = UBound(VARARRAY)
MsgBox (JJJ)
MsgBox (III)
' If Not .BOF Then .MoveFirst


For J = 0 To (JJJ)
For I = 0 To (III - 1)

TargetRange.Offset(J, (I * 2)).Value = VARARRAY(I, J)

Next
Next

End With
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub


---
Message posted from http://www.ExcelForum.com/

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Importing data from Excel to Access Linda Excel Discussion (Misc queries) 0 November 20th 07 04:35 PM
Problem importing Excel to Access Oregonnews Excel Worksheet Functions 3 April 23rd 07 09:37 PM
Problem importing data from Access BT Connect Excel Discussion (Misc queries) 2 January 21st 06 04:07 PM
Importing Data from Access into Excel vnvkatz Excel Discussion (Misc queries) 3 June 9th 05 05:02 PM
Importing Access data to Excel Chaprastee Excel Programming 1 May 10th 04 10:51 PM


All times are GMT +1. The time now is 03:44 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"