2012-01-28 76 views
1

需要數據庫建議。 我基本上需要一個宏,它可以針對超過一百萬個關鍵字的數據庫做一個vLookup表單(約50K條記錄)。VBA宏 - MS Access的數據庫建議

如果我使用MS Access 2007作爲vLookup的數據庫,過程會變得更快嗎?有沒有其他的方法可以通過使用不同的數據庫來使這個過程更快?

任何幫助或方向表示讚賞。謝謝大家的時間。

+0

編號Access數據庫中的100萬個關鍵字將會非常緩慢,更不用說重量級了。我會建議使用SQL數據庫。 – 2012-01-28 07:39:40

+4

@Siddarth Rout如果您認爲DQL服務器是從Excel升級的,那肯定會增加大量不必要的複雜性?訪問速度足夠快,就像在單個表上進行搜索一樣簡單,而且一百萬個單詞不是一個大型數據庫。 – Fionnuala 2012-01-28 09:41:49

回答

3

如果您已經將這些關鍵字存儲在Excel中,那麼值得看一下ADO將這些詞作爲表格讀取。這是一個簡單的例子,但它也足夠簡單,可以加入INNER或LEFT JOIN中要查找的單詞列表,並查找缺失和匹配的單詞。如果通過使用內聯連接字符串將關鍵字存儲在數據庫中,也可以這樣做。

Dim cn As Object 
Dim rs As Object 
Dim strFile As String 
Dim strCon As String 
Dim strSQL As String 
Dim s As String 
Dim i As Integer, j As Integer 

''This is not the best way to refer to the workbook 
''you want, but it is very convenient for notes 
''It is probably best to use the name of the workbook. 

strFile = ActiveWorkbook.FullName 

''Note that if HDR=No, F1,F2 etc are used for column names, 
''if HDR=Yes, the names in the first row of the range 
''can be used. 
'' 
''This is the ACE connection string, you can get more 
''here : http://www.connectionstrings.com/excel 

strCon = "Provider=Microsoft.Jet.OLEDB.12.0;Data Source=" & strFile _ 
    & ";Extended Properties=""Excel 12.0;HDR=Yes;IMEX=1"";" 

''Late binding, so no reference is needed 

Set cn = CreateObject("ADODB.Connection") 
Set rs = CreateObject("ADODB.Recordset") 

cn.Open strCon 

''Watch out for case sensitivity 
strSQL = "SELECT [ColumnName] " _ 
     & "FROM [Sheet1$] " _ 
     & "WHERE ColumnName ='" & strWord & "'" 

rs.Open strSQL, cn, 3, 3 

MsgBox rs.GetString 

''Tidy up 
rs.Close 
Set rs=Nothing 
cn.Close 
Set cn=Nothing