Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2007
    Posts
    13

    Unanswered: Checking for wrong value.

    I am using VB6 with MySql. I want a user to enter a reference and then when a command button is clicked, the columns associated with that reference are returned. What checks do I need to do if the record doesn't exist? Thank you.

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Are you using a simple SQL SELECT statement?
    Post the code you are using to pull out the values
    George
    Home | Blog

  3. #3
    Join Date
    Feb 2007
    Posts
    13
    Thank you for taking the time.

    Code:
    Dim rs1 As ADODB.Recordset
    Dim DB1 As New ADODB.Connection
    Dim sSQL1 As String
    
    sSQL1 = "select * from item_tracker where reference like ('" & txtReference.Text & "');"
    DB1.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False; UID=root@localhost ; database=mysql; option=3"
    DB1.Open "data source=myodbc"
    DB1.Execute ("USE Mysql;")
    Set rs1 = New ADODB.Recordset
    rs1.Open sSQL1, DB1, adOpenForwardOnly, adLockReadOnly, adCmdText
    txtItem1.Text = rs1.Fields("item1")
    txtItem2.Text = rs1.Fields("item2")
    txtItem3.Text = rs1.Fields("item3")
    txtItem4.Text = rs1.Fields("item4")
    I am checking to see if what is entered in 'reference' is in the database. If it is I want the record returned. If not I want an error message and then let the user try again. Right noe I get a runtime 3021 error 'Either EOF or BOF is true or the current record has been deleted...'
    Last edited by stevieooo; 02-26-07 at 17:45.

  4. #4
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Try adding this after the rs1.Open line:

    Code:
    If rs1.EOF Then
      Msgbox "No records found"
      Exit Sub 'or go to your exit point so the recordset gets set to nothing
    End If
    Paul

  5. #5
    Join Date
    Feb 2007
    Posts
    13
    Thank you very much. I added this code and that's what I was looking for. I appreciate your time on my basic qestion.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •