Share via

UPDATE pass-through query from code fails with error 3066

Anonymous
2010-09-21T23:53:59+00:00

"3066- Query must have at least one destination field." is the result of the following command:

DoCmd.OpenQuery "PriceUpdateQuery"

However, this is an UPDATE query, not a select query, and as such, THEY DO NOT HAVE OUTPUT FIELDS. 

I know there is a property that can be set, "Returns Records", and I have that property set to "no."

This does not seem to be a totally consistent problem, occasionally it lets one through.

How can I make this work?

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2010-09-22T01:51:06+00:00

Use the Execute method instead of OpenQuery:

CurrentDb.Execute "PriceUpdateQuery", dbFailOnError

with appropriate error trapping.


John W. Vinson/MVP

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Anonymous
    2010-09-23T00:08:29+00:00

    That works perfectly.  Thank you.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2010-09-22T01:39:11+00:00

    As I have run UPDATE queries like this on rare occassions I see no reason why you are getting this message.  So it would help if you would post the SQL of the query to see if there is something else.


    --

    Gina Whipp

    2010 Microsoft MVP (Access)

    Please post all replies to the forum where everyone can benefit.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2010-09-22T01:09:39+00:00

    Hi!!!!

    Please post your sql script, so we can help you

    or you can do what I do:

    'Update my table via my function...

    var_sql = "UPDATE my_table SET my_field = 'Another Option'"

    my_conn (var_sql)

    Public Function my_conn(var_sql As String)

    On Error GoTo Err_my_conn

    Dim cn As ADODB.Connection

    Dim cmd As ADODB.Command

      Set cn = New ADODB.Connection

      Set cmd = New ADODB.Command

      cn.ConnectionString = "DSN=MY_ODBC_CONNECTION"

      cn.Open

      Set cmd.ActiveConnection = cn

      cmd.CommandText = var_sql

      cmd.Execute

      cn.Close

      Set cmd = Nothing

      Set cn = Nothing

    Exit_my_conn:

        Exit Function

    Err_my_conn:

        MsgBox Err.Description

        Resume Exit_my_conn

    End Function

    :)


    I hope this helps, Bre-x just a regular user, not an expert

    Was this answer helpful?

    0 comments No comments