Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Excel Lookup in Access

What I have is this situation (in its simplest form)
I have an MS Access Database called Device Signals.mdb with a table called
Devices that contains 3 Fields (Primary Key, Acronym, Description). There
are 160,000 records in the database. Example of a worse case acronym in the
Acronym Field is L30_LST.SWI. The Description Field is simply the text
description of the Acronym. Both fields are formatted as text in MS Access.

In Excel I have a single spreadsheet I call (Sheet 1). Sheet 1 has 2 Rows.
The 2 rows can sometimes be 200 columns wide. Row 1 is Acronyms pasted from
field data, which is never in the same order. Row 2 is a place-holder for the
Descriptions.

What I need is some code (similar to VLOOKUP in Excel) to scan Row 1, got to
the Access database lookup the Acronyms in the Acronyms Field in Access and
copy the descriptions from the Descriptions Field into Row 2 of my Excel
Spreadsheet under the correct Acronym.
I have tried numerous versions of code without success, some work on
numbers, others on text, but none thus far have worked on alpha-numeric data
also taking into account spaces.

Can anyone Help

Thanks in advance

Romefucan

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Excel Lookup in Access

No code, so I don't know how you are trying to do this. But with an ADO
connection and .execute some SQL in a loop.
SQL="UPDATE Devices SET Description=" & Chr(34) & Cells(2,Counter) & chr(34)
& " WHERE Acronym=" & Chr(34) & Cells(1,Counter) & Chr(34)
Trap the error if the update fails.

Or you can try a BatchUpdate of a recordset from the original data.

NickHK

"Romefucan" wrote in message
...
What I have is this situation (in its simplest form)
I have an MS Access Database called Device Signals.mdb with a table called
"Devices" that contains 3 Fields (Primary Key, Acronym, Description).

There
are 160,000 records in the database. Example of a worse case acronym in

the
Acronym Field is L30_LST.SWI. The Description Field is simply the text
description of the Acronym. Both fields are formatted as text in MS

Access.

In Excel I have a single spreadsheet I call (Sheet 1). Sheet 1 has 2 Rows.
The 2 rows can sometimes be 200 columns wide. Row 1 is Acronyms pasted

from
field data, which is never in the same order. Row 2 is a place-holder for

the
Descriptions.

What I need is some code (similar to VLOOKUP in Excel) to scan Row 1, got

to
the Access database lookup the Acronyms in the "Acronyms Field" in Access

and
copy the descriptions from the "Descriptions Field" into Row 2 of my Excel
Spreadsheet under the correct Acronym.
I have tried numerous versions of code without success, some work on
numbers, others on text, but none thus far have worked on alpha-numeric

data
also taking into account spaces.

Can anyone Help

Thanks in advance

Romefucan



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Excel Lookup in Access

NickHK
Sorry my bust
Code as follows

Dim adoCN As ADODB.Connection
Dim strSQL As String

Const DatabasePath As String = "D:\Visual Engineering\Acronym.mdb"

'Function argument descriptions
'LookupFieldName - the field you wish to search
'LookupValue - the value in LookupFieldName you're searching for
'ReturnField - the matching field containing the value you wish to return

Public Function DBVLookUp(TableName As String, _
LookUpFieldName As String, _
LookupValue As String, _
ReturnField As String) As Variant
Dim adoRS As ADODB.Recordset
If adoCN Is Nothing Then SetUpConnection

Set adoRS = New ADODB.Recordset
strSQL = "SELECT " & LookUpFieldName & ", " & ReturnField & _
" FROM " & TableName & _
" WHERE " & LookUpFieldName & "=" & LookupValue & ";"
' If lookup value is a number then remove the two '
adoRS.Open strSQL, adoCN, adOpenForwardOnly, adLockReadOnly
If adoRS.BOF And adoRS.EOF Then
DBVLookUp = "Value not Found"
Else
DBVLookUp = adoRS.Fields(ReturnField).Value
End If
adoRS.Close
End Function

Sub SetUpConnection()
On Error GoTo ErrHandler
Set adoCN = New Connection
adoCN.Provider = "Microsoft.Jet.OLEDB.4.0" 'Change to 3.51 for Access 97
adoCN.ConnectionString = DatabasePath
adoCN.Open
Exit Sub
ErrHandler:
MsgBox Err.Description, vbExclamation, "An error occurred"
End Sub

Romefucan

"NickHK" wrote:

No code, so I don't know how you are trying to do this. But with an ADO
connection and .execute some SQL in a loop.
SQL="UPDATE Devices SET Description=" & Chr(34) & Cells(2,Counter) & chr(34)
& " WHERE Acronym=" & Chr(34) & Cells(1,Counter) & Chr(34)
Trap the error if the update fails.

Or you can try a BatchUpdate of a recordset from the original data.

NickHK

"Romefucan" wrote in message
...
What I have is this situation (in its simplest form)
I have an MS Access Database called Device Signals.mdb with a table called
"Devices" that contains 3 Fields (Primary Key, Acronym, Description).

There
are 160,000 records in the database. Example of a worse case acronym in

the
Acronym Field is L30_LST.SWI. The Description Field is simply the text
description of the Acronym. Both fields are formatted as text in MS

Access.

In Excel I have a single spreadsheet I call (Sheet 1). Sheet 1 has 2 Rows.
The 2 rows can sometimes be 200 columns wide. Row 1 is Acronyms pasted

from
field data, which is never in the same order. Row 2 is a place-holder for

the
Descriptions.

What I need is some code (similar to VLOOKUP in Excel) to scan Row 1, got

to
the Access database lookup the Acronyms in the "Acronyms Field" in Access

and
copy the descriptions from the "Descriptions Field" into Row 2 of my Excel
Spreadsheet under the correct Acronym.
I have tried numerous versions of code without success, some work on
numbers, others on text, but none thus far have worked on alpha-numeric

data
also taking into account spaces.

Can anyone Help

Thanks in advance

Romefucan




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Excel Lookup in Access

OK, I was looking at it the wrong way round.
Here's one way, but you need to hit the DB every time :

Dim Cell As Range
Dim SQL
For Each Cell In Range("acronyms")
SQL = "SELECT Description FROM <Table WHERE Acronym=" & Chr(34) &
Cell.Value & Chr(34)
adoRS.Open strSQL, adoCN, adOpenForwardOnly, adLockReadOnly
If adoRS.BOF And adoRS.EOF Then
Cell.Offset(0, 1).Value = "N/A"
Else
Cell.Offset(0, 1).Value = adoRS.Fields(ReturnField).Value
End If
Next

Depending on memory considerations, you could just get all the data locally,
then loop through the RS. Something like this psuedo code :

SQL = "SELECT Acronym, Description FROM <Table"
adoRS.Open strSQL, adoCN, adOpenForwardOnly, adLockReadOnly

For Each Cell In Range("acronyms")
adoRS.Find or Seek (depending on cursors etc)
If NothingFound Then
Cell.Offset(0, 1).Value = "N/A"
Else
Cell.Offset(0, 1).Value = adoRS.Fields(Found).Value
End If
Next

NickHK

"Romefucan" wrote in message
...
NickHK
Sorry my bust
Code as follows

Dim adoCN As ADODB.Connection
Dim strSQL As String

Const DatabasePath As String = "D:\Visual Engineering\Acronym.mdb"

'Function argument descriptions
'LookupFieldName - the field you wish to search
'LookupValue - the value in LookupFieldName you're searching for
'ReturnField - the matching field containing the value you wish to return

Public Function DBVLookUp(TableName As String, _
LookUpFieldName As String, _
LookupValue As String, _
ReturnField As String) As Variant
Dim adoRS As ADODB.Recordset
If adoCN Is Nothing Then SetUpConnection

Set adoRS = New ADODB.Recordset
strSQL = "SELECT " & LookUpFieldName & ", " & ReturnField & _
" FROM " & TableName & _
" WHERE " & LookUpFieldName & "=" & LookupValue & ";"
' If lookup value is a number then remove the two '
adoRS.Open strSQL, adoCN, adOpenForwardOnly, adLockReadOnly
If adoRS.BOF And adoRS.EOF Then
DBVLookUp = "Value not Found"
Else
DBVLookUp = adoRS.Fields(ReturnField).Value
End If
adoRS.Close
End Function

Sub SetUpConnection()
On Error GoTo ErrHandler
Set adoCN = New Connection
adoCN.Provider = "Microsoft.Jet.OLEDB.4.0" 'Change to 3.51 for Access

97
adoCN.ConnectionString = DatabasePath
adoCN.Open
Exit Sub
ErrHandler:
MsgBox Err.Description, vbExclamation, "An error occurred"
End Sub

Romefucan

"NickHK" wrote:

No code, so I don't know how you are trying to do this. But with an ADO
connection and .execute some SQL in a loop.
SQL="UPDATE Devices SET Description=" & Chr(34) & Cells(2,Counter) &

chr(34)
& " WHERE Acronym=" & Chr(34) & Cells(1,Counter) & Chr(34)
Trap the error if the update fails.

Or you can try a BatchUpdate of a recordset from the original data.

NickHK

"Romefucan" wrote in message
...
What I have is this situation (in its simplest form)
I have an MS Access Database called Device Signals.mdb with a table

called
"Devices" that contains 3 Fields (Primary Key, Acronym, Description).

There
are 160,000 records in the database. Example of a worse case acronym

in
the
Acronym Field is L30_LST.SWI. The Description Field is simply the text
description of the Acronym. Both fields are formatted as text in MS

Access.

In Excel I have a single spreadsheet I call (Sheet 1). Sheet 1 has 2

Rows.
The 2 rows can sometimes be 200 columns wide. Row 1 is Acronyms pasted

from
field data, which is never in the same order. Row 2 is a place-holder

for
the
Descriptions.

What I need is some code (similar to VLOOKUP in Excel) to scan Row 1,

got
to
the Access database lookup the Acronyms in the "Acronyms Field" in

Access
and
copy the descriptions from the "Descriptions Field" into Row 2 of my

Excel
Spreadsheet under the correct Acronym.
I have tried numerous versions of code without success, some work on
numbers, others on text, but none thus far have worked on

alpha-numeric
data
also taking into account spaces.

Can anyone Help

Thanks in advance

Romefucan






Reply
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
Lookup in Excel/Access monkey harry Excel Programming 6 June 22nd 06 08:27 AM
excel lookup, like access trav Excel Discussion (Misc queries) 1 February 22nd 06 02:31 AM
Lookup In Excel from Access Database ca1358 Excel Programming 0 January 27th 06 04:07 PM
Lookup from Excel to Access ca1358 Excel Programming 0 January 24th 06 08:59 PM


All times are GMT +1. The time now is 10:32 PM.

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"