473,385 Members | 1,824 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Query Works but when in VBA, it does not?

In Access 2003, I have a query set up like this:
Expand|Select|Wrap|Line Numbers
  1. SELECT [Comments],
  2.        [Comment ID] AS [Unique ID],
  3.        [Submitted Date]
  4.  
  5. FROM   tblMain
  6.  
  7. WHERE  ((([Submitted Date]) Between DateSerial(Year(Date()),Month(Date())-2,1)
  8.                                 And DateSerial(Year(Date()),Month(Date()),0))
  9.   AND   ([Subject1]<>"Online")
  10.   AND   ([Flags] Like "*Merger*"))
  11.    OR  (([Submitted Date] Between DateSerial(Year(Date()),Month(Date())-2,1)
  12.                               And DateSerial(Year(Date()),Month(Date()),0))
  13.   AND   ([Subject1]<>"Online")
  14.   AND   ([Flags] Like "*Merger*")
  15.   AND   ([Type]<>"Online"));
This query runs just fine and brings back 121 records.

However, when I put it in VBA like this, it brings back 0 records:
Expand|Select|Wrap|Line Numbers
  1. Set rst = New ADODB.Recordset
  2. rst.ActiveConnection = CurrentProject.Connection
  3. strqry = "WHERE (((tblMain.[Submitted Date]) Between DateSerial(Year(Date()),Month(Date())-2,1) And
  4. DateSerial(Year(Date()),Month(Date()),0)) AND ((tblMain.Subject1)<>'Online') AND ((tblMain.Flags) Like '*Merger*'))  " & _ "OR (((tblMain.[Submitted Date]) Between DateSerial(Year(Date()),Month(Date())-2,1) And DateSerial(Year(Date()),Month(Date()),0)) AND
  5. ((tblMain.Subject1)<>'Online') AND ((tblMain.Flags) Like '*Merger*') AND ((tblMain.Type)<>'Online'))" 
  6. rst.Open _ Source:="SELECT tblMain.Comments, tblMain.[Comment ID] AS [Unique ID], tblMain.[Submitted Date] FROM tblMain " & strqry, _ CursorType:=adOpenKeyset, _ 
  7. LockType:=adLockOptimistic, _ 
  8. options:=adCmdText
If I remove both tblMain.Flags like '*Merger*' from the code, it works so I know it has something to do with that - just can't figure out what.

Any assistance appreciated!
Sep 29 '09 #1

✓ answered by MikeTheBike

Hi

As you are using an ADO recordset then change this
'*Merger*'
to this
'%Merger%'

and see if that fixes it [use * for DAO recordsets] !


MTB

3 1542
MikeTheBike
639 Expert 512MB
Hi

As you are using an ADO recordset then change this
'*Merger*'
to this
'%Merger%'

and see if that fixes it [use * for DAO recordsets] !


MTB
Sep 29 '09 #2
Perfect! Thank you Mike....this is the first I've used a wildcard in VBA coding so that was new to me!! Learn something new everyday!!!
Sep 29 '09 #3
NeoPa
32,556 Expert Mod 16PB
Nice catch Mike :)

Alternatively of course, you could use DAO (instead of ADO). This is more compatible with Access's Jet SQL. ADO is more compatible with later standards though. See ANSI Standards in String Comparisons.
Sep 29 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: shank | last post by:
Per a previous suggestion, I'm trying to use a parametized query in Access 2002. The query functions properly in Access. Now I'm trying to call it from ASP. I'm using code I found at...
9
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
4
by: DebbieG | last post by:
I have a form based on this query: SELECT Students.LastSerDT, OtherInfo.Served, OtherInfo.HSGradYr, OtherInfo.ActivePart, OtherInfo.Served, Students.SSN, & ", " & & " " & AS Name,...
19
by: bdt513 | last post by:
I am trying to extract the values from a query using VBA. Specifically, I want to concatenate all the values of the "rosEmail" field from query "qselRosterEmailList" into one string (strEmails). I...
9
by: Mike Bridge | last post by:
I am using MS Access 2003, and I typed in a query in SQL view which was working fine. Now when I open it, it gives me the error "Join expression not supported". Apparently, Access "fixed" it for...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
36
by: Liam.M | last post by:
hey guys, I have one last problem to fix, and then my database is essentially done...I would therefore very much appreciate any assistance anyone would be able to provide me with. Currently I...
1
by: Ron | last post by:
Hi, Does a make table query have limitations that a select query doesn't have? This is my problem. I've got a make table query I'll call qrymktblTemp--it combines a few different tables and...
2
by: Cindy | last post by:
I have an Access 2003 database with a query that works fine on my PC but does not work on another PC. My PC has older versions of Access installed as well as 2003 - the other PC only has Access...
4
by: Uriah Piddle | last post by:
Hi Gang, In sql Server 2005, I am running a query with an nvarchar param in the WHERE clause like this: .. . . @Bar nvarchar .. . . Select * From Foo WHERE Foo.Bar = @Bar The problem:...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.