Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CreateQueryDef changes dropdown values to input parameters

Status
Not open for further replies.

marka1966

Programmer
Oct 9, 2002
19
0
0
US
I am creating a text string to insert into the CreateQueryDef command but the resulting query has the dropdown field values in brackets. They need to be in quotes.
(This is my first attempt at this type of thing in VB)
---------------------------------------------------------
Example:
Dim dbs As Database, IngQ As QueryDef, strSQL As String
Set dbs = CurrentDb

'Create a query string based on the form fields
strSQL = make_query_str()
'Create the qctual query in Access
Set IngQ = dbs.CreateQueryDef("CustomQuery", strSQL)

***********************************
Private Function make_query_str()
***********************************
' 15 steps here to read all the form fields and create the resulting string:

MyStr=&quot;SELECT <my fields here> INTO <my destination here> FROM <source tables here> WHERE (([ID's SPECIALTIES].SPECIALTY)=IM) AND ([NEW FINAL TABLE].TITLECODE)=30))&quot;

------------------------------------------------------------

The two problems that occur are:

1: The resulting QueryDef puts brackets around IM and 30
resulting in [IM] and [30]. When the Query is run it askes for input from the two bracketed values. These two values are retrieved from the dropdown sellection on the form.

2: I tried modifying the resulting string to have double quotes around the IM and 30 values by using &quot;\&quot;&quot; but MS VB converts them to &quot; \ &quot; &quot; (spaces before and after the \) as I exit the line. How can get VB to accept the quotes? Will accepting the quotes correct the problem?
 
try using &quot;&quot;&quot;&quot; instead of &quot;\&quot;&quot;
your thinking java or c++ for the escapequote and not VB



&quot;Every day is like a precious gift, you have to make it count&quot; James Birrell 1993-2001
 
Thanks.
I also discovered that VBA handles the single quote just like the double.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top