PDA

Click to See Complete Forum and Search --> : Problem with open statement


smh
Nov 7th, 2000, 03:39 PM
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

AdrianH
Nov 8th, 2000, 05:28 AM
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.

paulw
Nov 8th, 2000, 07:17 AM
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.

smh
Nov 8th, 2000, 08:14 AM
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