Hi Guys
In the table ScanDate has number data type and NewBatchNo has Text data type. The following code is meant to copy data from the table where scandate is between two dates and NewBatchNo is null. but when I run it then it stops responding. What could be the error in the following code.
Private Sub Workbook_Open()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim i As Long
i = 1
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Sheet1")
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=J:\WorkQueue.mdb;"
Set rs = CreateObject("ADODB.Recordset")
strsql = "select * from CocunutBatchTBL1 where ScanDate>=20131120 and Scandate<=20140829" rs.Open strsql, cn
Do While Not rs.EOF
If rs.fields("NewBatchNo") <> Null Then
ws.Cells(i, 1).Value = rs.fields("BatchNo")
i = i + 1
End If
Loop
End Sub
Bookmarks