We help IT Professionals succeed at work.
Get Started

MS Access 2010 VBA sql string

580 Views
Last Modified: 2012-06-27
Dear Experts,

  I'm composing a Where clause of an SQL Statement for OpenReport event in a MS Access 2010 Form.  The records showing go the report is different from the returning records when I issue the query directly on SQL Server 2005.  How do I make the SQL string in VBA be equivalent to the WHERE clause in the SQL Server 2005's sql statement?

The WHERE clause In SQL Server 2005:

WHERE
OrderDate = '10-10-2011' and OrderCountry ='USA'
And
( OrderCategories = 'A' or
  OrderSpecial =1          and
  OrderExpedite =0    
 )

Result Set

Date                Country     Category     SpecialOrder    ExpediteOrder
---------------------------------------------------------------------------
10-10-2011     USA            NULL             1                     0
10-10-2011     USA            A                   1                     0
10-10-2011     USA            A                   0                    0



The SQL string in OpenReport event of a MS Access Form:

sqlStr=
"[Order.OrderDate]=#" & Me.[txt_OrderDate] & "# and [Order.OrderCountry]='" & Me.[txt_Country] & "' and ([Order.OrderCategories]='" & Me.[txt_Category] & "' or [Order.OrderSpecial]=" & Me.[chk_OrderSpecial] & " and [Order.OrderExpedite]=" & Me.[chk_OrderExpedite] & ")"

Result Set

Date                Country     Category     SpecialOrder    ExpediteOrder
---------------------------------------------------------------------------
10-10-2011     USA            A                   1                     0
10-10-2011     USA            A                   0                    0



My Question

The result set from SQL Server 2005 is what I want.  How come the MS Access Report does not include the first record (with Category as NULL).  Is there anything wrong with my SQL string in VBA ?


Thank you!!!
Comment
Watch Question
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE