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!

Problem retrieving records

Status
Not open for further replies.

GhostWolf

Programmer
Jun 27, 2003
290
0
0
US
I think I need an extra pair of eyes - or two - to tell me what I'm missing.

Using VB6, ADO 2.5 and Access '03, I've created a small program to retrieve/update data. However, it's not retrieving!

Basically, the process is:
Code:
' in declarations: -----------------------------
Global cmdSQL As String
Global cnTrain As ADODB.Connection
Global cmTrain As ADODB.Command
Global rsTrain As ADODB.Recordset

' at AppInit: ----------------------------------
    dbName = App.Path + "\LogIn.mdb"
    Set cnTrain = New ADODB.Connection
    cnTrain.ConnectionString = _
        "Provider=Microsoft.Jet.OLEDB.4.0;" + _
        "Data Source=" + dbName + ";"
    cnTrain.Open
    Set cmTrain = New ADODB.Command
    cmTrain.ActiveConnection = cnTrain
    Set rsTrain = New ADODB.Recordset

' at user input: -------------------------------
    cmdSQL = "select * from TrainFile where " + _
             "SSN like '*" + txtSSN4 + "' and " + _
             "LName like '*" + txtLName + "*'"
    cmTrain.CommandType = adCmdText
    cmTrain.CommandText = cmdSQL
    rsTrain.Open cmTrain

The problem: rsTrain.BOF and rsTrain.EOF is always true. I can copy/paste cmTrain.CommandText into a query in the Access database, and it returns exactly the record(s) I expect to see.

After cnTrain.Open is executed, cnTrain.State=1 so I'm sure it's connected.

This is a process I use daily at work, (against DB2 and SQL Server databases), so I'm sure it should work.

I figure there's got to be some simple little thing I'm overlooking. If your eyes spot it, please let me know!
 
At first glance, you are using + to concatenate strings. Use & instead. + gives unreliable results, in certain cases trying to add string values instead of appending.

Cogito eggo sum – I think, therefore I am a waffle.
 
For what it's worth: I managed to get around the problem - by changing the Access interface to DAO 3.6, (but keeping ADO for the DB2 interface).

So far, everything's working just fine, even with + concatenation instead of &.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top