我的第一篇文章和我的第一個 MS Access 和 VBA 專案,以及真正的一般編碼......!
我有一個包含多個相似列的 Excel 資料表 txlsRegistration
[LON Option 1 (London Borough)]
[LON Option 1 (Railway Station)]
[BRS Option 1 (Postcode District)]
[BRS Option 1 (Public Transport Hub)]
等等
所有這些欄位都需要連接在選項編號上,以便以后有效地查詢它們。
所以我在 Access 中有一個選擇查詢,它將所有相同的選項編號欄位連接在一起并且作業正常。
SELECT txlsRegistration.ID, [txlsRegistration]![LON Option 1 (London Borough)] & [txlsRegistration]![LON Option 1 (Railway Station)] & [txlsRegistration]![BRS Option 1 (Postcode District)] & [txlsRegistration]![BRS Option 1 (Public Transport Hub)] AS ropOption1
FROM txlsRegistration
但是,欄位串列正在增長,我想要一種在選擇查詢中自動創建此連接的方法。
我在 VBA 中撰寫了一個名為GetFields的 For...Each 程序,它遍歷表的欄位并找到所有選項 1 欄位并將它們作為字串回傳,即[txlsRegistration]![LON Option 1 (London Borough)] & [txlsRegistration]![LON Option 1 (Railway Station)] & [txlsRegistration]![BRS Option 1 (Postcode District)] & [txlsRegistration]![BRS Option 1 (Public Transport Hub)]
當我使用我的函式創建一個新的選擇查詢時,如下所示
SELECT txlsRegistration.ID, GetFields() AS ropOption1
FROM txlsRegistration
它只是針對每條記錄回傳實際字符??串。我想要的是選擇查詢將字串識別為列名,而不是文字字串。有沒有辦法我可以做到這一點?
非常感謝我的第一次冒險......!
uj5u.com熱心網友回復:
我使用以前不知道的 QueryDefs 在 VBA 中創建了查詢!
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/434699.html
