Solved

Query with "AND"

Posted on 2003-10-31
3
187 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 500 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now