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 3853430
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:28:03+00:00 2026-05-19T17:28:03+00:00

I want to create a new record in the mailers table, where three fields

  • 0

I want to create a new record in the mailers table, where three fields would contain values: contacts_first_filter_id, mailer_states_id, created_at. And two of those values are based off queries from other tables and the last one is just the current time.

I’ve tried multiple ways to achieve this but none have worked. First I tried creating a query directly within sql design:

INSERT INTO mailers ( contacts_first_filter_id, mailer_states_id, created_at )
VALUES (DLookup("id","update_mailer_step_two"), DLookup("id","mailer_states" & "mailer_state = 'sent'"), Now());

This gives error ‘unknown’.

I also tried putting this in VBA editor and triggering it on a button click:

Private Sub Command6_Click()


        Dim CFF_ID As String, MS_ID As String, strSQL As String

        CFF_ID = "SELECT update_mailer_step_two.id FROM update_mailer_step_two"

        MS_ID = "SELECT mailer_states.id FROM mailer_states WHERE mailer_states.mailer_state = 'sent'"

        strSQL = "INSERT INTO mailers ( contacts_first_filter_id, mailer_states_id, created_at )VALUES ((" & CFF_ID & "),(" & MS_ID & "),NOW())"

        DoCmd.RunSQL strSQL

End Sub

This gives error:
“Query input must contain at least one table or query”.

I tried the recommendation below using INNER JOIN but while this produces no error, it appends 0 rows, presumably because there is no INNER JOIN link between update_mailer_step_two and mailer_states:

INSERT INTO mailers ( contacts_first_filter_id, mailer_states_id, created_at )
SELECT update_mailer_step_two.id, mailer_states.id, Now()
FROM update_mailer_step_two INNER JOIN mailer_states ON update_mailer_step_two.id = mailer_states.ID
WHERE mailer_states.mailer_state = 'sent';

mailer_states table is just a table that contains a mailer_state field with text. It’s pretty much just a lookup table that never changes.

update_mailer_step_2 contains one field called id, which contains a bunch of ids associated with contacts in database.
Hence, there’s no relationship at all between mailer_states and update_mailer_step_2.

** What I thought I would be able to do is when I create update_mailer_step_two, add a new column and default it with a value corresponding to mailer_states so that the INNER JOIN would work. Unfortunately, it appears you cannot do this in Access!

Another stackoverflow post mentioned you can:

SQL to add column with default value – Access 2003

But it is not working for me.

I have run out of ideas of how to place a query based off other table as a value to a query that is intended to create a new record in a table.

Thanks for response.

  • 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-19T17:28:04+00:00Added an answer on May 19, 2026 at 5:28 pm

    Your first approach (using a query containing calls to DLookup) should in principle work, but it has a syntax error. The suggestion by @HansUp to run each DLookup individually is a good one, and would help you to identify this (in the Visual Basic Editor, press Ctrl-G to show the intermediate window; the question mark before each expression in @HansUp’s example is required).

    Specifically, the ampersand in the second DLookup call is the string concatenation character, meaning that your current call is equivalent to:

    DLookup("id","mailer_statesmailer_state = 'sent'")
    

    Instead, change it to:

    DLookup("id","mailer_states", "mailer_state = 'sent'")
    

    EXTRA

    To insert one new row for each row in update_mailer_step_two, try this:

    INSERT INTO mailers ( contacts_first_filter_id, mailer_states_id, created_at )
    SELECT update_mailer_step_two.id,
           DLookup("id","mailer_states", "mailer_state = 'sent'"),
           Now()
    FROM update_mailer_step_two
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a new row in my database on a table that
I want to create a new object using Class::DBI. One of the fields of
I want to programmatically create a new column in an MS Access table. I've
I'm using Visual Basic 9 (VS2008) I want to create new Tabs as and
I want to create a new net.tcp://localhost:x/Service endpoint for a WCF service call, with
I want to create templates for base new reports on to have common designs.
I create a TextArea in actionscript: var textArea:TextArea = new TextArea(); I want it
I want create a drop shadow around the canvas component in flex. Technically speaking
I want to create a Java application bundle for Mac without using Mac. According
I want to create a client side mail creator web page. I know the

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.