7 Replies - 726 Views - Last Post: 03 February 2011 - 01:42 PM Rate Topic: -----

#1 H3O  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 15-October 10

Unable to return data from a database

Posted 26 January 2011 - 01:46 AM

Hi, am new to this forum and I've been working on a book store inventory system with vb 6.0 but my problem is I've unable to retrieve a specified data from the database. The error it displays is "Object required"
The code I used is:
Private Sub cmdSearch_Click()
    'On Error Resume Next
    Dim sql As String
        If txtSearch.Text = "" Then
            MsgBox "Type in the search field to proceed"
            Exit Sub
        End If
            sql = "SELECT * FROM booksReg WHERE book_title =" & Trim(txtSearch.Text) & ""
            connect
            rec.Open "booksReg", con, adOpenKeyset, adLockOptimistic
                If myrec.RecordCount = 1 Then
                    With myrec
                        lblBalance = .Fields("quantity")
                        lblAuthor = .Fields("author")
                        lblISBN = .Fields("quantity")
                        
                    End With
                Else
                    MsgBox "No record details exist for the supplied data"
                End If
            Set mycon = Nothing
                myrec.Close
                txtSearch.Text = ""
                optTitle.Value = False
                txtSearch.SetFocus
End Sub


This post has been edited by no2pencil: 26 January 2011 - 01:47 AM
Reason for edit:: Corrected code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Unable to return data from a database

#2 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5395
  • View blog
  • Posts: 27,389
  • Joined: 10-May 07

Re: Unable to return data from a database

Posted 26 January 2011 - 01:48 AM

Topic Moved to VB6.
Was This Post Helpful? 0
  • +
  • -

#3 Ahleki  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 55
  • Joined: 01-June 10

Re: Unable to return data from a database

Posted 26 January 2011 - 04:16 AM

Ahleki said:

Hey please indicate the line where the error is occurring

Was This Post Helpful? 0
  • +
  • -

#4 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: Unable to return data from a database

Posted 26 January 2011 - 08:01 AM

Three things:
1. if lblBalance is a label, then your assignment is wrong
lblBalance.Text = .Fields("quantity")



2. i see you open an object named rec
rec.Open "booksReg", con, adOpenKeyset, adLockOptimistic 


but then you use an object named myrec. Where is defined myrec? where do you open it?

3. this line
 rec.Open "booksReg", con, adOpenKeyset, adLockOptimistic 

shouldn't be
rec.Open sql, con, adOpenKeyset, adLockOptimistic 


?
Was This Post Helpful? 0
  • +
  • -

#5 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,606
  • Joined: 17-April 07

Re: Unable to return data from a database

Posted 31 January 2011 - 08:47 AM

i don't think so,
in which line did you get that error
Was This Post Helpful? 0
  • +
  • -

#6 lllllsp1d3rlllll  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 12
  • Joined: 01-February 11

Re: Unable to return data from a database

Posted 01 February 2011 - 02:41 AM

umm you shouldnt get any error cous u use on error and if u do thats a new one on what line do u get error data not found or missing components on a code line means u got the name of the componenet wrong or forgot to put it on your form

o also i guess u should know that u cant talk to a data base unlease its a server with a coded relay u cant only put and send info to a data base but u cant go back and see what u have put or what is stored on the data base but it wont relay back to you
Was This Post Helpful? -1
  • +
  • -

#7 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Unable to return data from a database

Posted 03 February 2011 - 01:33 PM

View Postlllllsp1d3rlllll, on 01 February 2011 - 02:41 AM, said:

umm you shouldnt get any error cous u use on error and if u do thats a new one on what line do u get error data not found or missing components on a code line means u got the name of the componenet wrong or forgot to put it on your form

o also i guess u should know that u cant talk to a data base unlease its a server with a coded relay u cant only put and send info to a data base but u cant go back and see what u have put or what is stored on the data base but it wont relay back to you

Come on spider, on error resume next is commented out. Also, I guess YOU should know that you can talk to a database just fine on your own pc with no server/workstation implications whatsoever.
Was This Post Helpful? 0
  • +
  • -

#8 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Unable to return data from a database

Posted 03 February 2011 - 01:42 PM

Ok, there are just too many things from other parts of your code that we can't tell. Ionut's stuff is all quite correct, and you need to pay attention to it. More:

line 9: no idea what "connect" means.
line 10: should say sql instead of "booksreg" as ionut says.
line 10: you open using a connection object called con, and we have no way of knowing whether you set it up correctly.
line 11-17, 22: you reference a myRec variable without ever opening it, as ionut mentions.
line 21: you set "mycon" to nothing, but we've never heard of it. When you set an object to nothing, it's best to do so in the same place that you created it.

"object required" could happen in any number of places where you haven't actually created an object. Looks to me like you're cutting and pasting code without fully understanding what it does. You might want to read up on creating ADO recordsets.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1