读书人

access路用,该怎么解决

发布时间: 2012-03-13 11:21:12 作者: rapoo

access路用
access路用

1.相路怎置;

2.怎把路全部改成相路;

[解决办法]
app.path
[解决办法]
app.path

[解决办法]
app.path

[解决办法]

VB code
App.Path
[解决办法]
'引用 Microsoft Activex Data Objects 2.5 Library
Option Explicit
Public Conn As New ADODB.Connection '定义数据连接字符串
Public Rs As New ADODB.Recordset '定义记录集
Dim Db$, DeskPath$, TmpStr$
Private Sub Form_Load()
DeskPath = GetDeskPath
Db = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DeskPath & "\分析修管理系\information.mdb;Persist Security Info=False"
Conn.CursorLocation = adUseClient
Conn.Open Db '打开数据库连接
TmpStr = "select * from 表名"
Rs.Open TmpStr, Conn, adOpenKeyset, adLockPessimistic
If Rs.RecordCount > 0 Then Rs.MoveFirst
'Set DataGrid1.DataSource = Rs
End Sub

Public Function GetDeskPath() As String
Dim WshShell
Set WshShell = CreateObject("Wscript.shell")
GetDeskPath = WshShell.SpecialFolders("Desktop")
End Function
[解决办法]
APP.PATH就是你的EXE程序所在的路径.
这下你该明白了吧.
你只要把EXE和数据库文件放在一个文件夹下面.那么在程序中凡是要使用数据录就写: APP.PATH & "\***.MDB"就代表了同文件夹下的这个数据库文件

读书人网 >VB

热点推荐