Guinaba
Board Regular
- Joined
- Sep 19, 2018
- Messages
- 233
- Office Version
- 2016
- Platform
- Windows
Hi guys,
I am learning how to handle recordsets in access, below I am opening a recordset and deleting all null values in the table. Using the sql below everything is ok
Set rs = db.OpenRecordset("SELECT * FROM tblTempColesForecast", dbOpenDynaset)
However, when I tried to add a sort or where condition on it, to organize the data better my loop code doesn't work anymore.
Set rs = db.OpenRecordset("SELECT * FROM tblTempColesForecast WHERE (((tblTempColesForecast.F2)<>""Vendor Description""))", dbOpenDynaset)
Not sure what I am missing?
I am learning how to handle recordsets in access, below I am opening a recordset and deleting all null values in the table. Using the sql below everything is ok
Set rs = db.OpenRecordset("SELECT * FROM tblTempColesForecast", dbOpenDynaset)
However, when I tried to add a sort or where condition on it, to organize the data better my loop code doesn't work anymore.
Set rs = db.OpenRecordset("SELECT * FROM tblTempColesForecast WHERE (((tblTempColesForecast.F2)<>""Vendor Description""))", dbOpenDynaset)
Not sure what I am missing?
VBA Code:
' Set data
strTableName = "tblTempColesForecast"
strFileName = VarFileName
blnHasHeadings = True
'Delete all data from temp table and temp query before importing again
Dim SQLDelete As String
SQLDelete = "Delete * From tblTempColesForecast"
DoCmd.RunSQL SQLDelete
' Import excel data into tblTempSys35
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, strTableName, strFileName, blnHasHeadings, "Data Extract Forecast!"
'*************Adjusting the data format in the table************************
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim rsSort As DAO.Recordset
Dim inx As Long
'Set the DAO database to current Access db
Set db = CurrentDb
'Open the table as the recordset
Set rs = db.OpenRecordset("SELECT * " & _
"FROM tblTempColesForecast", dbOpenDynaset)
'Test to make sure there are rows
If Not (rs.EOF And rs.BOF) Then
'Loop through the records
Do Until rs.EOF
For inx = 0 To rs.Fields.Count - 1 'numbering for members of a collection begins with zero, code loops starting with the zero member and ending with the value of the Count property minus 1
If IsNull(rs.Fields(inx).Value) Or Len(Trim(rs.Fields(inx).Value)) = 0 Then
Else: Exit For
End If
Next
If rs.Fields.Count = inx Then
rs.Delete
End If
rs.MoveNext
Loop
rs.Close 'Cleanup work
Set db = Nothing
Set rs = Nothing
End If