Re: How do I use the INSERT INTO Statement in VBA?



You cannot directly execute a SQL statement in VBA or via the Immediate Window. You have to utilize one of the provided commands - DoCmd.RunSQL or the .Execute method of a Database object (my personal new found friend). If you need help building the SQL statement, you can use the Query Builder to build it and test it and the just copy the SQL statement to your VBA procedure.

Unique Name wrote:
I am trying to enter data into a table from a form using the INSERT INTO Statement in VBA forAccess 2003. I type it as shown in the assistance(below) but keep getting errors. Is there something I am missing?

INSERT INTO target [(field1[, field2[, ...]])]
VALUES (value1[, value2[, ...])

Thanks
.



Relevant Pages

  • Re: Basics of VBA and SQL
    ... Dim strQry As String ... The DoCmd.OpenQuery method requires the NAME of a saved query, ... Using a SQL statement in VBA would require the DoCmd.RunSQL strQry ...
    (microsoft.public.access.modulesdaovba)
  • Re: Basics of VBA and SQL
    ... Dim strQry As String ... The DoCmd.OpenQuery method requires the NAME of a saved query, ... Using a SQL statement in VBA would require the DoCmd.RunSQL strQry ...
    (microsoft.public.access.modulesdaovba)
  • Re: dates as query criteria
    ... The # delimiter is correct for literal dates within the SQL statement (and ... in VBA also.) ... When adding paramters to a query, do not add the # to the parameter name. ...
    (microsoft.public.access.queries)
  • Re: Compile error
    ... Sounds like you are trying to write a SQL statement in the VBA code window. ... create code on the data tab and then copy and paste that code into the code ... the compilers highlights the "projstatus" right after SELECT and tells me ...
    (microsoft.public.access.forms)
  • Re: Equivalent of DROP TABLE IF EXIST?
    ... You will need to do this via VBA ... application reads a configuration file. ... I have to use a temporary table, the database tables and schema can't ... Is there anyway to suppress an SQL error when a SQL statement ...
    (microsoft.public.access.queries)

Loading