Results 1 to 4 of 4

Thread: Problem with open statement

  1. #1

    Thread Starter
    Addicted Member smh's Avatar
    Join Date
    Oct 2000
    Location
    South Dakota, USA
    Posts
    249
    The following is the code I am using to populate data to a form. I get an error saying that there is not current record. The global variable 'gstrLocation' does have a value at run-time. Does anyone know what my problem is?

    Private Sub Form_Load()

    Dim cnn As New ADODB.Connection
    Dim rst As New ADODB.Recordset

    'Open an ADO Connection
    cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=H:\Issues_files\issues.mdb;"

    'Open the ADO Recordset
    rst.Open "Select * from tblLog WHERE location = '" & gstrLocation & " ' ", cnn

    txtDateOccured = rst("dateoccured")
    txtTimeOccured = rst("timeoccured")
    txtDateReported = rst("datereported")
    txtReportedBy = rst("reportedby")
    txtLocation = rst("location")
    txtCubeNumber = rst("cubenumber")
    txtEnteredBy = rst("enteredby")
    txtIssueNumber = rst("issuenumber")
    txtCategory = rst("category")
    txtPriority = rst("priority")
    txtDownTime = rst("downtime")
    txtIssue = rst("issue")
    txtStatus = rst("Status")


    'End If


    End Sub


    smh

    Normal is boring...

    smh

  2. #2
    Lively Member
    Join Date
    Aug 2000
    Location
    Australia
    Posts
    82
    Sounds like the SQL Statement is not returning a recordset at all. Ensure that the gstrLocation variable actually is valid in your Location field.

    One way to test that you have returned record(s) from your SQL call is to use the RecordCount property. If rst.Recordcount > 0 then you have returned a recordset.

    Adrian.

  3. #3
    Fanatic Member
    Join Date
    Oct 2000
    Location
    London
    Posts
    1,008
    You have not tested for .BOF or .EOF - your record pointer is not currently on a valid record - DOES NOT mean that you have no records - use .MoveFirst to move to the first record after testing for .EOF/.BOF

    Cheers,

    Paul.
    Not nearly so tired now...

    Haven't been around much so be gentle...

  4. #4

    Thread Starter
    Addicted Member smh's Avatar
    Join Date
    Oct 2000
    Location
    South Dakota, USA
    Posts
    249

    Oops

    Well, sorry to have wasted your time, but I didn't double check the other programmers spelling too well. He for some reason hard-coded the combobox where we were selecting the global variable from, and had misspelled the option we just happened to be using for testing. So, my code was working after all, but the misspelling was not found in the database.

    Thanks anyway!

    smh
    Normal is boring...

    smh

Posting Permissions

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



Click Here to Expand Forum to Full Width