?
Solved

Query with "AND"

Posted on 2003-10-31
3
Medium Priority
?
235 Views
Last Modified: 2010-05-01
I'm trying to write a query in my Visual Basic application (Access as a database) as follow:
strSQL = "SELECT * FROM qryLearnerwithCourses "
strSQL = strSQL & "WHERE (qryLearnerwithCourses.Learner_ID = '"txtlearnerid.Text"') and (qryLearnerwithCourses.WCB_ID = '"companywcb.Text"') "

visual basics doesn't like this statement.  after moving away from that line i get the error: "expected end of statement"  and it changes the color of this code to red.
do you know what i'm doing wrong?
thank you
0
Comment
Question by:mapy
3 Comments
 
LVL 18

Accepted Solution

by:
bobbit31 earned 2000 total points
ID: 9660446
strSQL = strSQL & " WHERE (qryLearnerwithCourses.Learner_ID = '" & txtlearnerid.Text & "') and (qryLearnerwithCourses.WCB_ID = '" & companywcb.Text &"') "
0
 
LVL 29

Expert Comment

by:leonstryker
ID: 9660640
As a note

You should also check the value of you text boxes to make sure the user did not enter any single  or double quotes, since they will break your code.

Leon
0
 

Expert Comment

by:vkgonline
ID: 9669286
Yes, provided solution work. Note one more thing, sometimes user wants to enter a single code as the need of application. To handle it convert single code to double code.

Vinod
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question