Discussion Locked

Select an Access database from V Basic

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I am interested in using Visual Basic to select and open an Access database in a particular directory.

Thank you.

7 replies

by seagull data services

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 jackofalltech

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

This discussion is closed to new replies.