Tendai Mare
Tendai Mare

Reputation: 31

Querying data from database with vb6 and ms access with adodb

I want to select and view my data in the database, but it’s proving to be a challenge. Any advice on where I could be missing it? If I run this code even when the select criteria is met, it always returns search failed. Any help?

If txtSun.Text = "SUN" Then
    Set rst = New ADODB.Recordset
    Dim sSql As String
    sSql = "SELECT * FROM SundryProduct WHERE ProdCont='" & txt_con_code.Text & "'"
    rst.Open sSql, Cnn, adOpenForwardOnly, , adCmdText
    'rst.Open "SELECT * FROM SundryProduct WHERE ProdCont='" & txt_con_code.Text & "' ", Cnn, adOpenForwardOnly, , adCmdText
    If rst.EOF Then
    MsgBox ("SEARCH FAILED")
    Else
    MsgBox ("QUANTITY ORDERED  " & rst!QuantityOrdered & vbCrLf & "   My Load Number is   " & rst!LoadNumber)
    End If
End If

I am trying to find out if there is a record with a matching ProdCont value in the database, but since I was still trying to make this code work in the first place I have only put messageboxes in the code. I have even tried putting in an actual value that I know exists in the database but it still returns the search failed messagebox even though I know the value exists in the database.

Upvotes: 0

Views: 6901

Answers (2)

Ari Winard
Ari Winard

Reputation: 26

If rst.EOF = True Then '----> here
  MsgBox ("SEARCH FAILED")
Else
  MsgBox ("QUANTITY ORDERED  " & rst!QuantityOrdered & vbCrLf & "   My Load Number is   " &  rst!LoadNumber)
End If

Upvotes: 1

Fosterocalypse
Fosterocalypse

Reputation: 15

What happens is you try to just run a simple query i.e. select * from SundryProduct? I would start with that and build on it to eliminate the possibilty of coding/syntax causing the error message

Upvotes: 0

Related Questions