RichardMGreen
Well-known Member
- Joined
- Feb 20, 2006
- Messages
- 2,177
Hi all
I've got the following code which quite happily opens a database and returns query results to the specified sheet and range.
Now, the database I need to use now has to have a password to open it, so I've been trying to update the code to accept a username and password but with no luck.
What I've tried so far:-
Changed Persistant Security Info to true
Added username and password to the Conn.Open line.
I get an error message which says:-
"Cannot start your application. The workgroup information file is missing or opened exlusively by another user"
I know no-one else is in the database and I'm not entirely sure what a workgroup information file is.
Any help greatly appreciated.
I've got the following code which quite happily opens a database and returns query results to the specified sheet and range.
Code:
Dim conn As ADODB.Connection, rs As ADODB.Recordset, cmd As ADODB.Command
Dim wsData As Worksheet, wsDst As Worksheet, ws As Worksheet, wb As Workbook
Dim rngData As Range, rngDst As Range, qt As QueryTable
Dim strQry As String, strSQL As String, file As String, strConn As String
'----- Check if data retrieval should be bypassed - if so, go straight to file creation -----
Set wsData = Worksheets("Query_List")
file = wsData.Range("H2")
'----- Clear out old data and set up userform -----
maxquery = Sheets("Query_List").Range("A65535").End(xlUp).Row - 1
currentquery = 0
UserForm1.Show
UserForm1.Label1.Caption = "Refreshing Database Queries..."
UserForm1.ProgressBar1.Value = 0
UserForm1.Repaint
'----- Turn off calculations -----
Application.Calculation = xlCalculationManual
'----- Get all data -----
Set conn = New ADODB.Connection
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & file & ";Persist Security Info=False;"
conn.ConnectionString = strConn
conn.Open
Set rngData = wsData.Range("A2")
Set cmd = New ADODB.Command
On Error GoTo error_line
While rngData.Value <> ""
UserForm1.Label1.Caption = "Refreshing " & rngData.Value
UserForm1.Repaint
strQry = "[" & rngData.Value & "]"
strSQL = "SELECT * FROM " & strQry
offsetrow = 1
cmd.CommandType = adCmdText
cmd.CommandText = strSQL
cmd.ActiveConnection = conn
'----- Pick up information on where data is to go -----
Set wsDst = Worksheets(rngData.Offset(, 1).Value)
Set rngDst = wsDst.Range(rngData.Offset(, 2).Value)
'----- Retrieve data from database and insert into correct cells -----
Set rs = cmd.Execute
If Not IsNull(rngDst) Then rngDst.CopyFromRecordset rs
currentquery = currentquery + 1
'----- Make sure no data left to write and set up details for next query -----
error_line:
Err.Clear
On Error GoTo error_line
Set rs = Nothing
Set rngData = rngData.Offset(offsetrow)
UserForm1.ProgressBar1.Value = (currentquery / (maxquery + 1)) * 100
UserForm1.Repaint
Wend
Set conn = Nothing
Now, the database I need to use now has to have a password to open it, so I've been trying to update the code to accept a username and password but with no luck.
What I've tried so far:-
Changed Persistant Security Info to true
Added username and password to the Conn.Open line.
I get an error message which says:-
"Cannot start your application. The workgroup information file is missing or opened exlusively by another user"
I know no-one else is in the database and I'm not entirely sure what a workgroup information file is.
Any help greatly appreciated.