0

I'm opening an ADODB connection using a small function (this works fine) and I'm trying to pass a parameter into a Make Table Query. and getting an error that reads: 'an action query can not be used as a row source'

Here is the code that I'm testing.

Conn.Execute (sql)

With cmd
    .ActiveConnection = Conn
    .CommandType = adCmdText
    .CommandText = "SELECT * FROM c1GetLIVEDBnTF WHERE [AS OF DATE] = ?"
End With

cmd.Parameters.Append cmd.CreateParameter("[AS OF DATE]", adInteger, adParamInput, 10)
cmd.Parameters(0).Value = Range("ASOFDATE").Value

Set rs = cmd.Execute

I'm trying to pass a date from Range("ASOFDATE").Value (Excel worksheet) into an Access Make Table Query.

I found the example below, but couldn't get to to work.

Pass VBA Variable into Access Query(Excel VBA)

10
  • I'm not an expert in Access, but... If you try storing your Range("ASOFDATE").Value in a variable first and then you send the variable? I'm not sure if you can send an array as variable. Commented Oct 30, 2017 at 21:13
  • What's this piece of code: Conn.Execute (sql) doing? Where are you getting the error? Commented Oct 30, 2017 at 21:21
  • 1
    And is your "AS OF DATE" field really an adInteger type, or is it an adDate type? (That's probably not causing your error though.) Commented Oct 30, 2017 at 21:37
  • 1
    Sorry for not clarifying the setup better. The name of the MT Query is 'c1GetLIVEDBnTF' and it inserts all data into a table named 'bLIVEDBnTF'. Commented Oct 30, 2017 at 21:38
  • 2
    You can't SELECT from a Make Table query. You have to make the table, then select from the table you made. (Or change the make table query to just be a select query.) P.S. I don't know enough ADODB to write an answer without a lot of testing, so someone else can feel free to post a proper answer. Commented Oct 30, 2017 at 21:39

1 Answer 1

0

I finally got this to work.

Sub RunAccessQueries()

Dim db As DAO.Database
Dim ws As DAO.Workspace
Dim rst As DAO.Recordset

GoHere = ThisWorkbook.Path

ASOFDATE = Format(Range("ASOFDATE").Value, "MM/DD/YYYY")

Set ws = DBEngine.Workspaces(0)
Set db = DBEngine.OpenDatabase(GoHere & "\Main.mdb", False, False, "MS Access;PWD=pass")

sql = "INSERT INTO etc.;"
db.Execute sql, dbFailOnError
RecordsUpdated = db.RecordsAffected

db.Close

End Sub

The solution came form here.

Error 3219- Invalid Operation

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.