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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using an Access 2000 table in a VB exe program

Status
Not open for further replies.

fmg010

Technical User
Jun 19, 2001
7
0
0
US
I have alot of experience using access 2000 but very little VB. I want to create a little application that looks up an airport in a huge list of airports using the airports Id code. All of the data is in an access table. How would I link the table to a Form in a Visual Basic project. Mike Garcia
Associate Manager
PCS Sector
Motorola
FMG010@email.mot.com
 
Here's a sample function that will take a SQL statement and return an ADO recordset. It will work for any OLEDB provider, including Jet3.51 or 4 you will use with Access.

Substitute your own errorhandling and connection string. The connect string should not be hardcoded. It was changed here for clarity.


'Returns an ADO recordset
Public Function OpenADORecordSet(ByVal sSQL As String, Optional ByVal adCursorType As CursorTypeEnum = adOpenKeyset, Optional ByVal adLockType As LockTypeEnum = adLockOptimistic) As ADODB.Recordset
Dim objConn As ADODB.Connection
Dim rsTmp As ADODB.Recordset
Dim strConnect as String

On Error GoTo ErrorHandler


strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Data\Airports.mdb;Persist Security Info=False"


Set rsTmp = CreateObject("ADODB.Recordset")
Set objConn = CreateObject("ADODB.Connection")

objConn.Open strConnect

With rsTmp
.CursorLocation = adUseClient
.Open sSQL, objConn, adCursorType, adLockType
Set .ActiveConnection = Nothing
End With

Set OpenADORecordSet = rsTmp

ExitProc:
On Error Resume Next
Set objConn = Nothing
Set rsTmp = Nothing
Exit Function
ErrorHandler:
LogError "OpenADORecordSet", "SQL: " & sSQL
Resume ExitProc
End Function




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top