วิธีในการสร้าง Path ให้กับ Application (ให้มันถูกต้อง)
Friday, September 7, 2012
0
comments
             | 
        
            Sub OpenDataBase()
Dim Conn As New ADODB.Connection
Dim RS As New ADODB.RecordSet
' หากต้องนำไปใช้ร่วมกับโปรแกรมย่อยอื่่นๆ ควรประกาศ Conn และ RS ในลักษณะของ Global น่ะขอรับ
Dim DB_File As String, SQLStmt As String
  DB_File = App.Path
  If Right$(DB_File, 1) <> "\" Then DB_File = DB_File & "\"
  DB_File = DB_File & "DATABASE.MDB"
  ' Open a connection.
  Set Conn = New ADODB.Connection
  Conn.ConnectionString = _
    "Provider = Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source = " & DB_File & ";" & _
    "Persist Security Info = False"
  Conn.Open
  ' ตัวอย่างนำไปใช้งานกับการสร้าง RecordSet
  SQLStmt = "SELECT * FROM tblSample"
  Set RS = Conn.Execute(SQLStmt, , adCmdText)
End Sub 
0 comments:
Post a Comment