I need to query a database table then write 3 of the 4 fields to an excel spreadsheet. Once that line is written I need to update the ‘sentback’ field to ‘Y’. This was the initial field used in the where clause. So the whole idea is to query, write, and change to flag to ‘Y’ so I do not select those records again.
I have half the code working here. I know i can probably use the DoCmd somehow, but cant quite figure it out.
Other records could be added to the database during the running of the routine, so the update must happen on the current record set used in the do while in order to avoid setting the flag on records that may not have been sent.
Any help is greatly appreciated
Dim strSQL As String
strExcelFile = "C:\MySpreadSheet.xls"
strWorksheet = "WorkSheet1"
strDB = "C:\track.accdb"
strTable = "manifests2"
Set db = CurrentDb
'If excel file already exists, you can delete it here
If Dir(strExcelFile) <> "" Then Kill strExcelFile
strSQL = "SELECT manifests2.[Shipment ID], manifests2.[Courier Service Level], manifests2.[Other Tracking],manifests2.[sentback] FROM " & "[" & strTable & "] WHERE (((manifests2.[sentback]) = 'N') and ((manifests2.[Other Tracking]) <> NULL))"
Set rs = db.OpenRecordset(strSQL)
Do While Not rs.EOF
rs.Edit
rs("sentback").Value = "Y"
rs.Update
rs.MoveNext
Loop
End Sub
If Shipment ID is a unique identifier, which it seems to be, you can use the Excel file to update the table, thereby ensuring that only the records that are in the file are marked sent.
There are some problems. For example, you have spaces in field (column) names. This is going to make life ever more difficult for you. You seem to have chosen text for
sentbackwhen YesNo (boolean) would be a more obvious choice. Nothing is ever equal or not equal tonull, somethingis nulloris not null.