If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > help a beginner with ADO??

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-11-02, 14:55
VTTW VTTW is offline
Registered User
 
Join Date: Dec 2002
Posts: 1
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
adoRs.MoveNext
Loop

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
adoRs.Close
adoConn.Close
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??

Thanks,
Mark
Reply With Quote
  #2 (permalink)  
Old 12-11-02, 21:32
rnealejr rnealejr is offline
Registered User
 
Join Date: Feb 2002
Posts: 2,232
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 ?
Reply With Quote
  #3 (permalink)  
Old 01-02-03, 11:52
roman22 roman22 is offline
Registered User
 
Join Date: Jan 2003
Location: Chicago, IL, USA
Posts: 8
This might help...
Try putting parenthesis around the .EOF .BOF part, like this:

If Not (adoRs.EOF And adoRs.BOF)
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On