[nfbcs] vb ado code

Bryan Schulz b.schulz at sbcglobal.net
Thu Apr 9 03:56:47 UTC 2009


hi,

I'd like to know if anybody on here is familiar with visual basic 6.0 and coding access database ado commands.
i have a program working with dow style code and an access '97 database and am trying to update it to xp and ado code.
The problem is with using an unfamiliar method of coding how to open a table.


Private Sub LoadTeams()
'load the competing teams from the database
'Dim our variables
'Create bridge to data
Dim DbPath As String
Dim DbConn As ADODB.Connection
Dim RS As ADODB.Recordset
Dim sqlLine As String
Dim Game As Integer
Dim i As Integer
Dim iRecs As Integer

'find the database
DbPath = App.Path
If Right$(DbPath, 1) <> "\" Then DbPath = DbPath & "\"
DbPath = DbPath & "BB-tourney.mdb"

' Open a connection.
Set DbConn = New ADODB.Connection
DbConn.ConnectionString = _
    "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & DbPath & ";" & _
    "Persist Security Info=False"
DbConn.Open

sqlLine = sqlLine & "SELECT * FROM "
sqlLine = sqlLine & "all_2004_teams"
sqlLine = sqlLine & " ORDER BY game_code"
'MsgBox "sql line = " & sqlLine, vbOKOnly, "sql check"

' Get the records
'** problem **
Set RS = DbConn.Execute(sqlLine, , adCmdText)
'It complains about missing parameters
'The second parameter is how many records are affected and is optional
'Anyone recognize what it should say?

'Get the teams from the database
i = 0
For Game = 1 To 8
    optTeam(i).Caption = RS.Fields("team_a").Value
    i = i + 1
    optTeam(i).Caption = RS.Fields("team_b").Value
    i = i + 1
    RS.MoveNext
Next Game

'Close the connection
DbConn.Close
Set DbConn = Nothing
End Sub

Bryan Schulz
The BEST Solution
www.best-acts.com



More information about the NFBCS mailing list