Re: How to use SQL variables in VBA



schoultzy wrote:

Hello, I have the following SQL code:

DECLARE draw_num2 int

SELECT draw_num2 = max (draw_num)+ 1 --THIS LINE IS MY PROBLEM
FROM hdx_housing_assign_master

I want to execute this code in Access VBA, however, I am having a
problem understanding how to accomplish this same task in VBA. My
problem is that the variable is manipulated within the SQL statement
and I do not know how to re-produce that functionality in VBA.


I don't know what variety of SQL you are using, but the
"normal" way of doing that is:

SELECT max(draw_num)+ 1 AS draw_num2

--
Marsh
MVP [MS Access]
.



Relevant Pages

  • How to use SQL variables in VBA
    ... I want to execute this code in Access VBA, however, I am having a ... problem understanding how to accomplish this same task in VBA. ...
    (microsoft.public.access.queries)
  • 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: 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)