Programmatic query problem

G

Guest

Hi
in a project I'm developing I linked AS400 table. I try to execute the
following code

Set cmd = New ADODB.Command
cmd.ActiveConnection = Application.CurrentProject.Connection
cmd.CommandText = " SELECT DATALIB_TPRZT00F.ZCDTIT AS [Codice Titolo] " & _
" FROM DATALIB_TPRZT00F " & _
" WHERE (((DATALIB_TPRZT00F.ZCDTIT) Like '*20001400')) "

Set rst = cmd.Execute
Debug.Print rst(0)

but I got the following error "Current record corresponds to the beginning
or to the end of file or it was deleted. To execute the operation required it
is necessary to have a current record" when I execute the last statement.
If I try to execute the same query by query windows it works fine.
Can anyone tell me what could be the problem?
TIA
Marco
 
D

Douglas J. Steele

ADO uses % as the wildcard, not *.

However, you should never assume that data is going to be returned.

Set rst = cmd.Execute
If Not rst.BOF And Not rst.EOF Then
Debug.Print rst(0)
Else
Debug.Print "No data found"
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top