LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 449
Default Access into Excel

This can't be right:
Data Source=" & ThisWorkbook.Path & "Q:\IT\Database Masters\Guarantees2.mdb

try
MsgBox strConn
somewhere and see what it reads.

HTH. Best wishes Harald



"richard gregson" wrote in message
...
I am trying to return a value from an access database by looking up a value
in excel. This is the code I have - but I cannot get it to work - I keep
getting a run time error not a valid file name at the cnn.open part -
please help!

Sub getProjectDescFromAccess()
'Needs reference the Axtive X Library 2.0 or higher
Const projectIDColumn = "A"
Const projectDescColumn = "J"
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sSQL As String, strConn
Dim looper As Long
Dim cellPointer As Variant

'Q:\IT\Database Masters\Guarantees2.mdb
'
strConn = "Provider=Microsoft.Jet.OLEDB.4.0; " _
& "Data Source=" & ThisWorkbook.Path & "Q:\IT\Database
Masters\Guarantees2.mdb;Persist Security Info=False"
Set cnn = New ADODB.Connection
cnn.Open strConn

For looper = 2 To Range(projectIDColumn & Rows.Count).End(xlUp).Row
Set cellPointer = Worksheets("Sheet1").Range(projectIDColumn & looper)
'If you project number field is text use this sSQL
sSQL = "SELECT tblBank Gtes.* FROM tblBank Gtes WHERE(((tblBank
Gtes.GTEE_NMBR)='" & cellPointer & "'));"
'If you project number field is number use this sSQL
'sSQL = "SELECT tblBank Gtes.* FROM tblBank Gtes WHERE" (((tblBank
Gtes.GTEE_NMBR)=" & cellPointer & "));"
Set rs = New ADODB.Recordset

rs.Open sSQL, cnn, adOpenStatic, adLockOptimistic
If Not IsNull(rs.Fields("GTEE_NMBR").Value) Then
Range(projectDescColumn & looper) = rs.Fields("GTEE_NMBR").Value
End If
rs.Close
Set rs = Nothing
Next looper

cnn.Close
Set cnn = Nothing
End Sub


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I link Excel to a dynamically column named access table? Kay[_6_] Excel Programming 0 January 24th 08 11:42 AM
Importing data from Access to Excel, but I need to vary the table from Access Liz L. Excel Programming 3 June 6th 06 02:12 AM
Data from Excel to Access Table Secret Squirrel Excel Discussion (Misc queries) 11 December 2nd 05 11:58 PM
Excel data to an Access table Les[_2_] Excel Programming 6 October 13th 03 07:53 PM
updating Access table with Excel data newbie[_2_] Excel Programming 2 July 11th 03 03:06 AM


All times are GMT +1. The time now is 08:50 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"