Database programming using ADO in Visual Basic is simple and convenient but it requires you to setup a DSN entry for the database you're going to deal with. The following source code tell you how to programmatically specify the database driver and access database directory without building up a DSN entry.
Open a new project and add the following two form files.
'********** Start of "frmMain.frm"
VERSION 5.00
Begin VB.Form frmMain
Caption = "Main"
ClientHeight = 2700
ClientLeft = 60
ClientTop = 345
ClientWidth = 4455
LinkTopic = "Form1"
ScaleHeight = 2700
ScaleWidth = 4455
StartUpPosition = 3 'Windows Default
Begin VB.TextBox txtDBPath
Height = 375
Left = 240
TabIndex = 1
Text = "G:Program FilesMicrosoft Visual StudioVB98"
Top = 600
Width = 3975
End
Begin VB.CommandButton cmdOpenDB
Caption = "Open"
Height = 975
Left = 240
TabIndex = 0
Top = 1320
Width = 3975
End
Begin VB.Label Label1
Caption = "Path to NWIND.MDB"
Height = 255
Left = 240
TabIndex = 2
Top = 240
Width = 3855
End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cmdOpenDB_Click()
FileSystem.ChDir txtDBPath.Text
frmDB.Show
End Sub
'********** END of "frmMain.frm"
'********** START of "frmDB.frm"
VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "msadodc.ocx"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "msdatgrd.ocx"
Begin VB.Form frmDB
Caption = "Form2"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form2"
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 'Windows Default
Begin MSDataGridLib.DataGrid DataGrid1
Bindings = "frmDB.frx":0000
Height = 2175
Left = 120
TabIndex = 0
Top = 240
Width = 4455
_ExtentX = 7858
_ExtentY = 3836
_Version = 393216
HeadLines = 1
RowHeight = 15
BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ColumnCount = 2
BeginProperty Column00
DataField = ""
Caption = ""
BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED}
Type = 0
Format = ""
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 3076
SubFormatType = 0
EndProperty
EndProperty
BeginProperty Column01
DataField = ""
Caption = ""
BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED}
Type = 0
Format = ""
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 3076
SubFormatType = 0
EndProperty
EndProperty
SplitCount = 1
BeginProperty Split0
BeginProperty Column00
EndProperty
BeginProperty Column01
EndProperty
EndProperty
End
Begin MSAdodcLib.Adodc Adodc1
Height = 375
Left = 120
Top = 2640
Width = 1695
_ExtentX = 2990
_ExtentY = 661
ConnectMode = 0
CursorLocation = 3
IsolationLevel = -1
ConnectionTimeout= 15
CommandTimeout = 30
CursorType = 3
LockType = 3
CommandType = 2
CursorOptions = 0
CacheSize = 50
MaxRecords = 0
BOFAction = 0
EOFAction = 0
ConnectStringType= 1
Appearance = 1
BackColor = -2147483643
ForeColor = -2147483640
Orientation = 0
Enabled = -1
Connect = "Provider=MSDASQL;Driver={Microsoft Access Driver (*.mdb)};Dbq=nwind.mdb;Uid=Admin;Pwd=;"
OLEDBString = "Provider=MSDASQL;Driver={Microsoft Access Driver (*.mdb)