Solved

DataControl.RecordSource= How to pass a SQL to MSSQL Server 6.5??

Posted on 1998-06-24
4
148 Views
Last Modified: 2010-05-03
I have recently upsized the back end of my app from Access 97 to MSSQL Server 6.5. One DataControl originally has the following statement:
Data1.RecordSource="SELECT * FROM Staff WHERE StaffID='" & txtStaffID.Text & "'"
Data1.Refresh
However, it does not work with MSSQL Server 6.5 since it goes thru the ODBC layer. I read from "Help" and know that I can set the RecordSource = QueryDef.some_kind_of_property
to pass the SQL statement and then do the Refresh. But how??? Can anyone give me an example???
0
Comment
Question by:ppmb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 6

Expert Comment

by:clifABB
ID: 1464208
The code you have will work.  You have another problem.
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1464209
Let me clarify.

Your original code:
Data1.RecordSource="SELECT * FROM Staff WHERE StaffID='" & txtStaffID.Text & "'"

Is fully acceptable, even when you go through an ODBC layer.

Are you sure txtStaffID.Text contains data?
Are you sure the tables were rebuilt in SQLServer the same as they were in Access (table and field names the same)?

Are you getting any errors?

0
 
LVL 2

Accepted Solution

by:
Jagar earned 70 total points
ID: 1464210
If StaffID is an Autonumber field then take out the single quotes it should read
Data1.RecordSource="SELECT * FROM Staff WHERE StaffID= " & txtStaffID.Text

Like everyone said this SQL statement will work, but this looks to be your problem not the statement itself.
0
 

Author Comment

by:ppmb
ID: 1464211
I read the comments from expert clifABB first and found out that it really is not the problem from the statement. Instead, it is from setup and the DBA. I am gonna credit clifABB the points but clifABB didn't have an answer for me to give points. How am I gonna do this???
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

733 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