PDA

View Full Version : Retrieve data from Access



Sorezz
07-11-2013, 07:03 PM
I new to vba....

Sub SelectMonth()
' Variable Declaration
Dim i As Integer
Dim SelectSQL As String, WhereSQL As String
Dim Stamp As String, text As String, datacnt1 As Integer

Set dbsc = OpenDatabase(Systempath)


datacnt1 = 0
x1 = 10
y1 = 10
x2 = 10
y2 = 11
x3 = 10
y3 = 12
x4 = 10
y4 = 13
x5 = 10
y5 = 14
w1 = 0
w2 = 0
w3 = 0
w4 = 0
w5 = 0
i = 1


' Build SQL Text
SelectSQL = ""
SelectSQL = "SELECT Month FROM WK "

'SelectSQL = SelectSQL
Set dnset1 = dbsc.OpenRecordset(SelectSQL)

datacnt1 = dnset1.RecordCount




' Dyanset Move First Position
dnset1.MoveFirst

Do While dnset1.EOF = False

If IsNull(dnset1.Fields(0)) Then

Else
Cells(x1, y1) = dnset1.Fields(0)
x1 = x1 + 1
'w1 = w1 + 1
'SelectDistrictName
'SelectNewCountryCode
'SelectCatType
'SelectMaterial

End If

dnset1.MoveNext
Loop

GoTo SelectDynasetClose

SelectDynasetClose:
dnset1.Close

End Sub





The records all print first value. If print second records it show runtime error 3265. Items not found this collection

Thanks in advance....

joms
07-12-2013, 01:39 AM
check out this link:
it might give you an idea on how to get the thing done.

http://support.microsoft.com/kb/306125/en-us