Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7415925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:23:32+00:00 2026-05-29T07:23:32+00:00

I need to query a database table then write 3 of the 4 fields

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:23:33+00:00Added an answer on May 29, 2026 at 7:23 am

    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.

    strExcelFile = "C:\MySpreadSheet.xls"
    'strWorksheet = "WorkSheet1"
    'strDB = "C:\track.accdb"
    strTable = "manifests2"
    
    Set db = CurrentDb
    
    ''The sheet takes its name from the query. This connection string depends
    ''on the versions of Access and Excel that you are using.
    cn = "[Excel 8.0;HDR=YES;IMEX=2;ACCDB=YES;DATABASE=" & strExcelFile & "].[OutDat$]"
    
    ''If excel file already exists, you can delete it here
    If Dir(strExcelFile) <> "" Then Kill strExcelFile
    
    ''Just use an existing query.
    ''If a query is to be created/updated each time, you need to check
    ''if it exists and either create or update as appropriate.
    
    ''strSQL = "SELECT m.[Shipment ID], m.[Courier Service Level], " _
           & "m.[Other Tracking], m.[sentback]  " _
           & "FROM [" & strTable & "] As m " _
           & "WHERE m.[sentback] = 'N' And m.[Other Tracking] Is Not Null"
    
    ''db.CreateQueryDef "OutDat", strSQL
    
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "OutDat", strExcelFile
    
    strSQL = "UPDATE [" & strTable & "] SET SentBack = 'Y' " _
           & "WHERE [Shipment ID] In (SELECT [Shipment ID] FROM " _
           & cn & ")"
    
    db.Execute strSQL
    

    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 sentback when YesNo (boolean) would be a more obvious choice. Nothing is ever equal or not equal to null, something is null or is not null.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Database has tables Photos and PhotoAlbums. I need a query that will select all
I currently need to execute a database query that involves data from three separate
I need to write an SQL-Query for a csv-export. I have a table stores,
I would like to construct a sqlite3 database query in python, then write it
I need to query a database which is designed so what a NVARCHAR column
I need to query the database to get the column names , not to
I need to query a Sybase database which has a lot of data in
I need to run a RLIKE query on a database mmoved from MySQL to
I need to be able to query a SharePoint database for survey results. The
I'm using CodeIgniter's Active Record class to query the MySQL database. I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.