Comparing fields between excel and access and fill
What i wanted to know is how do i get a vb application reading an excel f开发者_StackOverflow中文版ile and a access database at same time, make them compare the fields and fill fields that are null.
for example:
Excel has this columns and fields:
Adress, postal code
avenue whatever no.30 ny, null(postal code doesnt have a value)
Access has this columns and fields:
Adress, postal code
avenue whatever no.30 ny, 2700-168
how do i make the access database fill the field in the excel file?
Thanks in advance
I presume you want to call the code from Excel in this instance. You could try something like this pseudocode example:
Sub foo()
Dim db as DAO.Database
Dim rs as Recordset
Dim ws as Worksheet
Dim i as Long
Set db = Workspaces(0).OpenDatabase("C:\MyPath\MyDatabase.mdb", ReadOnly:=True)
Set rs = db.OpenRecordset("Name of DB Table")
Set ws = ActiveSheet
i = 2
ws.Range("A1") = "Address"
ws.Range("B1") = "Postal Code"
rs.MoveFirst
Do While Not rs.EOF
ws.Range("A" & i) = rs("Table Address Column Name")
ws.Range("B" & i) = rs("Table Postal Code Column Name")
rs.MoveNext
i = i + 1
Loop
rs.close
db.close
Set db = Nothing
Set rs = Nothing
Set ws = Nothing
End Sub
精彩评论