Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2002

    Unanswered: help a beginner with ADO??

    I'm trying to get this snipet of code to work for me, but I'm having trouble. The code is to, connect to my db (works), loop trough/.additem from !jobnumber (works) & populate some textboxes on my form (I'm only trying to get "txtJobName" to populate for the time being, but it doesn't work).

    Here's my code:
    Private Sub Form_Load()

    Dim adoConn As ADODB.Connection
    Dim adoRs As ADODB.Recordset
    Dim connStr As String
    Dim strSql As String

    Set adoConn = New ADODB.Connection

    Set adoRs = New ADODB.Recordset

    connStr = "Provider=Microsoft.Jet.OLEDB.3.51;" _
    & "Data Source=C:\program files\dci job folders\db1.mdb"

    adoConn.Open connStr
    adoRs.Open "job", adoConn

    Do Until adoRs.EOF
    cmbJobNumber.AddItem adoRs!jobnumber

    cmbJobNumber.ListIndex = 0

    strSql = "select job.jobname from job where job.jobnumber is " & cmbJobNumber.Text
    If Not adoRs.EOF And adoRs.BOF Then '<---
    Me.txtJobName.Text = adoRs.Fields!jobname '<---
    Else '<---
    Me.txtJobName.Text = "" '<---

    End If
    Set adoRs = Nothing
    Set adoConn = Nothing
    End Sub

    I'm accustom to VBA, but I'm trying to learn VB. The trouble I'm having is getting txtJobName to populate with the correct fields value, it only the "" as coded in the else statement. I've tried other combinations of code, but I start getting BOF & EOF run-time errors. Can someone fill me in as to why this code doesn't work??


  2. #2
    Join Date
    Feb 2002
    The reason is that before the text box code you are looping until the recordset hits eof. Since it hits eof, you will never see anything from this recordset unless you do a movefirst/moveprevious. However, what do you want to show in the text box - only 1 value can be displayed ?

  3. #3
    Join Date
    Jan 2003
    Chicago, IL, USA
    This might help...
    Try putting parenthesis around the .EOF .BOF part, like this:

    If Not (adoRs.EOF And adoRs.BOF)

Posting Permissions

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