SQL and Visual Basic (VB 5)

Posted on 1998-11-26
Last Modified: 2013-11-25
DataCustomer.RecordSource = "Select * from Customers where Customer_ID = " & UserInputByCustomerID

This works for a number, but not for text. How can i get this SQL to work from a Access database to access a record for somebody's last name.  
Question by:altecjjf

Accepted Solution

kamall earned 100 total points
ID: 1447020
Change it to:
DataCustomer.RecordSource = "Select * from Customers where Customer_ID = '" & UserInputByCustomerID & "'"

Note that the string must be between two single quotation marks ' '.

Author Comment

ID: 1447021
The SQL is correct now, but i get a data mismatch error. I think i might be able to figure it out, but do you know what it could be? Thanks Again

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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 is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…

813 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

18 Experts available now in Live!

Get 1:1 Help Now