Select an Access database from V Basic
I am interested in using Visual Basic to select and open an Access database in a particular directory.
Thank you.
Web Development
I am interested in using Visual Basic to select and open an Access database in a particular directory.
Thank you.
You can use the Common Dialogs control (Add Microsoft Common Dialogs from Project|Components) to locate the file you want to open.
Once you have the file name and path, you can then open it using the method of your choice, e.g. ADO/DAO.
by hurdk
Here is some sample code:
Public Const DB_NAME = "\\some_server\vol1\...\access.mdb"
Public g_dbNetW As Database 'main database object
Public g_qdTop10 As QueryDef
Public g_rsTop10 As Recordset
Public g_sQuery As String
*
* *
*
g_sQuery = "SELECT [field1], [field2], ... From [table1] " & _
"Where (" & _
"([table1].[DATE OCCURRED] >= #" & cboMonth.Text & "/01/" & cboYear.Text & "#) AND " & _
"([EPS TICKETS].[DATE OCCURRED] < #" & sDate & "#)"
If cboDept.Text <> "ALL" Then
g_sQuery = g_sQuery & " AND ([table1].[ASGNDEPT] = """ & cboDept.Text & """)"
End If
g_sQuery = g_sQuery & ")"
Set g_dbNetW = OpenDatabase(DB_NAME, , ReadOnly:=True)
Set g_qdTop10 = g_dbNetW.CreateQueryDef("")
g_qdTop10.SQL = g_sQuery
Set g_rsTop10 = g_qdTop10.OpenRecordset()
DoEvents
Sleep 1
g_rsTop10.MoveFirst
sbStatus.SimpleText = "Processing records"
While Not g_rsTop10.EOF
If g_rsTop10![PROBLEM DESCRIPTION] <> vbNull Then
ProcessTicket
End If
g_rsTop10.MoveNext
Wend
g_rsTop10.Close
g_dbNetW.Close
Ralph
by hurdk
by timfox2
Written by Terry Kreft and distributed by Dev Ashish
http://www.mvps.org/access/api/api0002.htm
This is the simplest method to use and it's pretty muh plug and play.
While we're on the subject, you can use the (Ken Getz) FileOpen or FileSave using this one :
http://www.mvps.org/access/api/api0001.htm
Good luck
Tim
by hurdk
by hurdk
This discussion is closed to new replies.
Sort by Trending