View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Lost! Lost! is offline
external usenet poster
 
Posts: 1
Default Database Connection from Excel

Hello,

I have written the following code into an Excel Sheet
command button which attempts to access a query that is
housed in a Access DB and export the data into a excel
sheet.

Private Sub CommandButton1_Click()

'Create a Recordset from all the records in the
DuplicateCandidate Query
Dim sEcruiterMaster As String
Dim conn As New ADODB.Connection
Dim rs As ADODB.Recordset

'Inform user what command will do
Beep
MsgBox "This will run the Duplicate Candidate Report for
Campus.", vbOKCancel, "Information"

'Finds and run the query from the database
EcruiterMaster = "\\Pathe to Ecruiter Campus DB"
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
& EcruiterMaster & ";"
conn.CursorLocation = adUseClient
Set rs = conn.Execute("BM_DuplicateCandidate", ,
adCmdQuery)

'Create a new workbook in Excel
Dim xlApp As Object
Dim xlBook As Object
Dim xlSheet As Object

Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
xlApp.Visible = True

'Transfer the data to Excel
xlSheet.Range("A2").CopyFromRecordset rs

End Sub

However, when I run the code, I get the error "Error in
the DLL". I used this same command button a year ago and
it worked without any problems. Since then i have not used
it and when I came back to it this year i keep getting the
same error.

I have checked all my references to ensure that have been
inserted and am unsure what else to do.

Any help anyone can provide is much appreciated.

Many thanks

Very Lost!