Lookup Data from Access

mrkntdrk

New Member
Joined
Feb 29, 2004
Messages
34
I have an excel sheet with two Col of numbers. This data is changed on a daily basis (e.g. add new rows)

Col_1___Col_2
34356____5
34356____7
78974____6
24568___(Blank)
59764____1

I also have a two very large Access Databases with many rows and col of data. I would like to bring it in selectively per col_1 and col_2 to the excel sheet.

Database(A) = col_3
Database(B) = col_4

The results should look like this...

Col_1___Col_2__Col_3__Col_4
34356____5____John____ABC
34356____7____Tim____(blank)
78974____6___(blank)__FGH
24568__(blank)_Jack___XYZ
59764____1____Bob____wds

Thanks
 
I am still struggling with matching up my excel table to the blank fields in the access tables.

Does anyone have any ideas?
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Mark

What is the structure of the COL_2 column in each of the tables in the relevant databases? Number, Text??? And is the blank a null, space???


Tony
 
Upvote 0
Mark

OK try
Code:
Sub aaa()
 Dim wrkjet As Workspace
 Dim db1, db2 As database
 Dim rs1, rs2 As Recordset

 Set wrkjet = CreateWorkspace("", "admin", "", dbUseJet)
 Set db1 = wrkjet.OpenDatabase("c:\temp\test2.mdb")
 Set db2 = wrkjet.OpenDatabase("c:\temp\test3.mdb")
 For Each ce In Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row)
  If IsEmpty(ce.Offset(0, 1)) Then
    Set rs1 = db1.OpenRecordset("select [access_table1].COL_3 from [access_table1] where [access_table1].col_1 = " & ce & " And [access_table1].col_2 is null")
    Set rs2 = db2.OpenRecordset("select [access_table2].COL_4 from [access_table2] where [access_table2].col_1 = " & ce & " And [access_table2].col_2 is null")
  Else
    Set rs1 = db1.OpenRecordset("select [access_table1].COL_3 from [access_table1] where [access_table1].col_1 = " & ce & " And [access_table1].col_2 = " & ce.Offset(0, 1))
    Set rs2 = db2.OpenRecordset("select [access_table2].COL_4 from [access_table2] where [access_table2].col_1 = " & ce & " And [access_table2].col_2 = " & ce.Offset(0, 1))
  End If

  rs1.MoveFirst
  ce.Offset(0, 2).Value = rs1.Fields("COL_3")
  rs2.MoveFirst
  ce.Offset(0, 3).Value = rs2.Fields("COL_4")
 Next ce


 db1.Close
 db2.Close
 wrkjet.Close
End Sub


Tony
 
Upvote 0

Forum statistics

Threads
1,214,870
Messages
6,122,021
Members
449,060
Latest member
LinusJE

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top