msaccess-将SQL查询存储在外部文件中 [英] msaccess - storing sql query in external file
本文介绍了msaccess-将SQL查询存储在外部文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不喜欢MsAccess的内置文本编辑器,而是想使用外部文本编辑器.
I dislike the built in text editor for MsAccess and would like to use an external text editor.
扩展上一个问题:有没有办法将sql查询存储在外部文件中并让MsAccess引用它?
Is there a way I can store the sql query in an external file and have MsAccess reference it?
推荐答案
如果可以通过VBA设置记录源,则可以使用以下方法:
If you are OK with setting the recordsource via VBA, then you can use this:
Public Function ReadTxt(filePath As String) As String
Dim oFSO As FileSystemObject
Set oFSO = New FileSystemObject
Dim oFS As TextStream
If oFSO.FileExists(filePath) Then
On Error GoTo Err
Set oFS = oFSO.OpenTextFile(filePath)
' read file
ReadTxt = oFS.ReadAll
'Debug.Print IIf(oFS Is Nothing, "file is closed", "file opened")
oFS.Close
Else
MsgBox "The file path is invalid.", vbCritical, vbNullString
Exit Function
End If
Exit Function
Err:
MsgBox "Error while reading the file.", vbCritical, vbNullString
oFS.Close
Exit Function
End Function
用法:ReadTxt("C:\TempFolder\YourQuery.txt")
但是,摆弄很多,为什么不直接将其(SQL)剪切并粘贴到Access中呢?
However, it's a lot of fiddling around, why not just cut and paste it (the SQL) into Access?
这篇关于msaccess-将SQL查询存储在外部文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文