SQL Statement via Form Coding

  • Thread starter Thread starter Bill
  • Start date Start date
B

Bill

Hi everyone,



I need your help to check the SQL Statement below if I did the right thing.
I tried and tried and it doesn't work. Your help would be much
appreciated.



Thanks







strSQL = "SELECT Table A.FIELD #1, Table A.FIELD #2, Table A.FIELD #3, Table
A.FIELD #4, Table A.Field #5, Table A.FIELD #6, Table A. FIELD #7, Table A.
FIELD #7, Table A. FIELD #7, Table A. FIELD #8, Table A. FIELD #9, Table A.
FIELD #10, Table B.Field #11, Table B.Field #12, Table B.Field #13, Table B.
FIELD #14, Table B. FIELD #15, Table B. FIELD #16, Table C. FIELD #17, Table
C. FIELD #18, Table C. FIELD #19, Table C. FIELD #20, Table C. FIELD #21,
Table C. FIELD #22, Table C. FIELD #23, Table C. FIELD #24, Table C. FIELD
#25, Table C. FIELD #26, Table C. FIELD #27, Table C. FIELD #28, Table C.
FIELD #29, Table C. FIELD #30, Table C. FIELD #31, Table C. FIELD #32, Table
C. FIELD #33, Table C. FIELD #34, Table D. FIELD #35, Table D. FIELD #36,
Table D. FIELD #37, Table D. FIELD #38, Table D. FIELD #39, Table D. FIELD
#40, Table D. FIELD #41, Table D. FIELD #42, Table D. FIELD #43, Table D.
FIELD #44, Table D. FIELD #45" _

& "((TABLE A LEFT JOIN TABLE B ON Table A.FIELD #1 = Table
B.FIELD #1) LEFT JOIN TABLE C ON Table A.FIELD #1 = TABLE C.EMPNO) LEFT JOIN
TABLE D ON Table A.FIELD #1 = Table D.FIELD #1" _

& "WHERE (((Table A.FIELD #4)='AUTO') AND ((Table D.FIELD #35)
Between [START Date] And [END Date]));"
 
"Did the right thing"?

What is the context of your question? What do you mean "right thing"? What
do you mean "doesn't work"?
 
Bill said:
I need your help to check the SQL Statement below if I did the right thing.
I tried and tried and it doesn't work.

strSQL = "SELECT Table A.FIELD #1, Table A.FIELD #2, Table A.FIELD #3, Table
A.FIELD #4, Table A.Field #5, Table A.FIELD #6, Table A. FIELD #7, Table A.
FIELD #7, Table A. FIELD #7, Table A. FIELD #8, Table A. FIELD #9, Table A.
FIELD #10, Table B.Field #11, Table B.Field #12, Table B.Field #13, Table B.
FIELD #14, Table B. FIELD #15, Table B. FIELD #16, Table C. FIELD #17, Table
C. FIELD #18, Table C. FIELD #19, Table C. FIELD #20, Table C. FIELD #21,
Table C. FIELD #22, Table C. FIELD #23, Table C. FIELD #24, Table C. FIELD
#25, Table C. FIELD #26, Table C. FIELD #27, Table C. FIELD #28, Table C.
FIELD #29, Table C. FIELD #30, Table C. FIELD #31, Table C. FIELD #32, Table
C. FIELD #33, Table C. FIELD #34, Table D. FIELD #35, Table D. FIELD #36,
Table D. FIELD #37, Table D. FIELD #38, Table D. FIELD #39, Table D. FIELD
#40, Table D. FIELD #41, Table D. FIELD #42, Table D. FIELD #43, Table D.
FIELD #44, Table D. FIELD #45" _

& "((TABLE A LEFT JOIN TABLE B ON Table A.FIELD #1 = Table
B.FIELD #1) LEFT JOIN TABLE C ON Table A.FIELD #1 = TABLE C.EMPNO) LEFT JOIN
TABLE D ON Table A.FIELD #1 = Table D.FIELD #1" _

& "WHERE (((Table A.FIELD #4)='AUTO') AND ((Table D.FIELD #35)
Between [START Date] And [END Date]));"


Excuse me, but you can't possibly have real tables named
Table A, etc, and fields named Field #1, etc, can you??

If you are just paraphrasing your real code, don't. Post a
copy/paste of your actual code.

If that is your real code, then I don't see how anyone,
including the author (you?) can understand what it's
supposed to do. At the very least, you must enclose any
name name includes a space (or other nonalphanumeric)
character in square brackets [ and ]. Better yet, you
should use meaningful, descriptive names to help you follow
what you intended to do.

To help you debug VBA code that constructs an SQL statement,
temporarily add a
MsgBox strSQL
statement to display the result in its final form. This
will at least allow you to see the SQL statement and
visually inspect it for obvious errors such as missing
brackets, quotes, spaces, commas, etc.
 
Back
Top