Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ODBC To Access

Status
Not open for further replies.

myasin78

Programmer
Jan 26, 2004
50
US
Hello All,
I setup ODBC DSN name to connect to MS Access DB.

Public Function OpenDB() As String
Dim buffer As String
buffer = "DSN=name;UID=;PWD="
OpenDB = buffer
End Function

Private Sub cmdStart_Click()
Dim GetDBConn As String
Dim sql As String

GetDBConn = OpenDB()
sql = "select INV from PO"
rst.Open sql, cnn, adOpenDynamic, adLockOptimistic

With rst
If Not .EOF And Not .EOF Then
.MoveNext
MsgBox (rst.Fields(0))
End If
End With

cnn.Close 'close database
End Sub

I got a message error on line:
rst.open sql, cnn, addOpenDynamic,........
the exact error is "The Connection cannot be used to perform this operation. It is either closed or invalid in this context"

Do you see anything wrong with my code?

thanks,
myasin
 
I forget to do:
cnn.open buffer

thanks anyway, it is working now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top